如何将bmp转存为jpg格式?(50分)

  • 主题发起人 主题发起人 ufo!
  • 开始时间 开始时间
U

ufo!

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要在自己的程序中读取bmp格式的图片并要将其转换为jpg的格式,用流操作,请大虾们
不吝赐教!
 
uses Jpeg;

procedure CopyBmpToJpeg(BmpFile,JpegFile:string);
var
Bmp:TBitmap;
Jpeg:TJPEGImage;
begin
Bmp:=TBitmap.create;
Jpeg:= TJpegImage.Create;
try
Bmp.LoadFromFile(BmpFile);
Jpeg.Assign(Bmp);
Jpeg.SaveToFile(JpegFile);
finally
Bmp.Free;
Jpeg.Free;
end;
end;
 
image1.picture.savetofile('***.jpg');
 
mybmp:=tbitmap.Create ;
with mybmp do
try
loadfromfile(filelistbox1.FileName);
myjpeg:=tjpegimage.Create ;
with myjpeg do
begin
assign(mybmp);
compressionquality:=trackbar1.Position;
compress;
if savepicturedialog1.Execute then
begin
SaveToFile(savepicturedialog1.FileName+'.jpeg');
// form1.workfile := savepicturedialog1.FileName;//+'.bmp';
//SAVE1CLICK(SENDER);
//form1.ImageChage ;
end;
//savetofile('D:/delphi/FlipReverseRotate/sunflower0.jpeg');
free;
end;
finally;
free;
 
都被你们说了
 
以上这些方法都是要先保存到硬盘上的,有无可以直接用流在内存操作,我是要把bmp转成
jpg后附加到另一个程序的后面,作成类似电子贺卡那样的东西的.
 
uses Jpeg;

procedure BmpToJpegStream(BmpFile:string;var JpegStream:TMemoryStream);
var
Bmp:TBitmap;
Jpeg:TJPEGImage;
begin
Bmp:=TBitmap.create;
Jpeg:= TJpegImage.Create;
try
Bmp.LoadFromFile(BmpFile);
Jpeg.Assign(Bmp);
Jpeg.SaveToStream(JpegStream);
finally
Jpeg.Free;
Bmp.Free;
end;
end;
 
function Bmp2Jpg(Bmp: TBitmap; Quality: Integer = 100): TJpegImage;
begin
Result := nil;
if Assigned(Bmp)
then begin
Result := TJpegImage.Create;
Result.Assign(Bmp); {It′s all folks...}
Result.CompressionQuality := Quality;
Result.JPEGNeeded; {Key method...}
Result.Compress;
end;
end;
 
jpg.Assign(bitmap); //将图象转成JPG格式
jpg.SaveToStream(m1); //将JPG图象写入流中
jpg.free;
 
谢谢大家,接受答案了
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
767
DelphiTeacher的专栏
D
D
回复
0
查看
809
DelphiTeacher的专栏
D
后退
顶部