bmp.assign(jpg);
bmp.savetofile('.\img\img.jpg');
当执行次数大于一时,保存的img.jpg始终是第一次获取的,为何?
10 个解决方案
#1
bmp.assign(jpg);中jpg变化了吗
#2
急!急!急!....
#3
jpg是变化的
#4
bmp:=TBitmap.Create;
bmp.assign(jpg);
bmp.savetofile('.\img\img.jpg');
bmp.Free;
#5
把你的完整代码贴出看看
#6
测试源码:
var
sFile: TsearchRec;
ImgJpeg: TJPEGImage;
ImgBmp: TBitmap;
begin
ImgJpeg := TJPEGImage.create;
ImgBmp := TBitmap.create;
if FindFirst('D:\testImg\*.jpg',faAnyFile,sFile) = 0 then
repeat
ImgJpeg.loadfromfile(''D:\testImg\'+sFile.Name);
ImgBmp.assign(nil);
ImgBmp.assign(ImgJpeg);
ImgBmp.savetofile('D:\Img\tImg.jpg');
until FindNext(sFile) <> 0;
FindClose(sFile);
ImgJpeg .free;
ImgBmp.free;
end;
sFile.Name是不同的图像文件名,图像也是不同的,单在保存tImg.jpg后仅是第一次取的图像,不在更新。
var
sFile: TsearchRec;
ImgJpeg: TJPEGImage;
ImgBmp: TBitmap;
begin
ImgJpeg := TJPEGImage.create;
ImgBmp := TBitmap.create;
if FindFirst('D:\testImg\*.jpg',faAnyFile,sFile) = 0 then
repeat
ImgJpeg.loadfromfile(''D:\testImg\'+sFile.Name);
ImgBmp.assign(nil);
ImgBmp.assign(ImgJpeg);
ImgBmp.savetofile('D:\Img\tImg.jpg');
until FindNext(sFile) <> 0;
FindClose(sFile);
ImgJpeg .free;
ImgBmp.free;
end;
sFile.Name是不同的图像文件名,图像也是不同的,单在保存tImg.jpg后仅是第一次取的图像,不在更新。
#7
to—》qiufenglangzi
你这样的方式也试过,不管用。
你这样的方式也试过,不管用。
#8
我测试过,没问题的,不过ImgBmp.savetofile('C:\tImg.jpg');你总是保存成这个文件,是不是有点问题呀,你能分得出是哪个吗,对于每个文件,总该取个不同的名字吧
#9
我找到问题所在了,刚刚的代码我有所见。
请重新看下:
const
imgdir = 'D:\Work\票据影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
//imgsrc.Assign(nil);
imgsrc.Assign(jpg);
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
这段代码是问题的根源。
请重新看下:
const
imgdir = 'D:\Work\票据影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
//imgsrc.Assign(nil);
imgsrc.Assign(jpg);
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
这段代码是问题的根源。
#10
const
imgdir = 'D:\Work\影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
///////////////////////////////////////////////
imgsrc.Assign(jpg);// error
or
imgsrc:=jpg; // rigth
////////////////////////////////////////////////
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
实质性测试通过,仅供参考!
imgdir = 'D:\Work\影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
///////////////////////////////////////////////
imgsrc.Assign(jpg);// error
or
imgsrc:=jpg; // rigth
////////////////////////////////////////////////
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
实质性测试通过,仅供参考!
#1
bmp.assign(jpg);中jpg变化了吗
#2
急!急!急!....
#3
jpg是变化的
#4
bmp:=TBitmap.Create;
bmp.assign(jpg);
bmp.savetofile('.\img\img.jpg');
bmp.Free;
#5
把你的完整代码贴出看看
#6
测试源码:
var
sFile: TsearchRec;
ImgJpeg: TJPEGImage;
ImgBmp: TBitmap;
begin
ImgJpeg := TJPEGImage.create;
ImgBmp := TBitmap.create;
if FindFirst('D:\testImg\*.jpg',faAnyFile,sFile) = 0 then
repeat
ImgJpeg.loadfromfile(''D:\testImg\'+sFile.Name);
ImgBmp.assign(nil);
ImgBmp.assign(ImgJpeg);
ImgBmp.savetofile('D:\Img\tImg.jpg');
until FindNext(sFile) <> 0;
FindClose(sFile);
ImgJpeg .free;
ImgBmp.free;
end;
sFile.Name是不同的图像文件名,图像也是不同的,单在保存tImg.jpg后仅是第一次取的图像,不在更新。
var
sFile: TsearchRec;
ImgJpeg: TJPEGImage;
ImgBmp: TBitmap;
begin
ImgJpeg := TJPEGImage.create;
ImgBmp := TBitmap.create;
if FindFirst('D:\testImg\*.jpg',faAnyFile,sFile) = 0 then
repeat
ImgJpeg.loadfromfile(''D:\testImg\'+sFile.Name);
ImgBmp.assign(nil);
ImgBmp.assign(ImgJpeg);
ImgBmp.savetofile('D:\Img\tImg.jpg');
until FindNext(sFile) <> 0;
FindClose(sFile);
ImgJpeg .free;
ImgBmp.free;
end;
sFile.Name是不同的图像文件名,图像也是不同的,单在保存tImg.jpg后仅是第一次取的图像,不在更新。
#7
to—》qiufenglangzi
你这样的方式也试过,不管用。
你这样的方式也试过,不管用。
#8
我测试过,没问题的,不过ImgBmp.savetofile('C:\tImg.jpg');你总是保存成这个文件,是不是有点问题呀,你能分得出是哪个吗,对于每个文件,总该取个不同的名字吧
#9
我找到问题所在了,刚刚的代码我有所见。
请重新看下:
const
imgdir = 'D:\Work\票据影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
//imgsrc.Assign(nil);
imgsrc.Assign(jpg);
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
这段代码是问题的根源。
请重新看下:
const
imgdir = 'D:\Work\票据影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
//imgsrc.Assign(nil);
imgsrc.Assign(jpg);
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
这段代码是问题的根源。
#10
const
imgdir = 'D:\Work\影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
///////////////////////////////////////////////
imgsrc.Assign(jpg);// error
or
imgsrc:=jpg; // rigth
////////////////////////////////////////////////
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
实质性测试通过,仅供参考!
imgdir = 'D:\Work\影像\';
procedure TForm1.FormCreate(Sender: TObject);
begin
imgBitmap := TBitmap.Create;
imgsrc := TJPEGImage.Create;
jpg := TJPEGImage.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
imgBitmap.Free;
imgsrc.Free;
jpg.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sFile: TSearchRec;
filestream: tmemorystream;
begin
if FindFirst(imgdir+'*.jpg',faAnyFile,sFile) = 0 then
repeat
if (Trim(sFile.Name)='.') or (Trim(sFile.Name)='..') then
Continue;
if (sFile.Attr and faAnyFile) = sFile.Attr then
begin
try
filestream:= tmemorystream.Create;
filestream.LoadFromFile(imgdir+sfile.Name);
filestream.SaveToFile('.\img\F.jpg');
jpg.LoadFromStream(filestream);
jpg.SaveToFile('.\img\F_0.jpg');
///////////////////////////////////////////////
imgsrc.Assign(jpg);// error
or
imgsrc:=jpg; // rigth
////////////////////////////////////////////////
imgsrc.SaveToFile('.\img\F_1.jpg');
imgBitmap.Assign(nil);
imgBitmap.Assign(imgsrc);
imgBitmap.SaveToFile('.\img\F_2.jpg');
Sleep(3000);
finally
filestream.Destroy;
end;
end;
until FindNext(sFile) <> 0 ;
FindClose(sFile);
实质性测试通过,仅供参考!