将jpg转换成bmp的问题?(100)

  • 主题发起人 主题发起人 Jary_mail
  • 开始时间 开始时间
J

Jary_mail

Unregistered / Unconfirmed
GUEST, unregistred user!
bmp.assign(nil);bmp.assign(jpg);bmp.savetofile('./img/img.jpg');当执行次数大于一时,保存的img.jpg始终是第一次获取的,为何?
 
急!急!急!....
 
不要用TBITMAP去处理jpg图像,要用TJpegImage
 
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); 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);正确方式: //******以下方法是正确的***********// imgsrc:=jpg; imgsrc.SaveToFile('./img/F_1.jpg'); imgBitmap.Assign(nil); imgBitmap.Assign(imgsrc); imgBitmap.SaveToFile('./img/F_2.jpg'); //*********************//测试通过...
 
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);实质性测试通过,仅供参考!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部