M
miaoyuli
Unregistered / Unconfirmed
GUEST, unregistred user!
程序读取JPG文件,进行压缩后通过Timage控件显示出来,我目前的实现代码如下,但是在压缩后转成BMP准备读入Timage控件之前报错“JPEG error #41”,请问应如何修改?
var
fromImage:TImage;
tmpJpeg:TJPEGImage;
tmpBitmap:TBitmap;
MemStr:TMemoryStream;
begin
MemStr:=TMemoryStream.Create;
MemStr.Clear;
MemStr.LoadFromFile('c:/1.jpg');
MemStr.Seek(0,0);
tmpjpeg:=TJPEGImage.Create;
tmpjpeg.LoadFromStream(MemStr);
tmpjpeg.CompressionQuality := 5;
//tmpjpeg.JPEGNeeded;
tmpjpeg.Compress;
//tmpjpeg.DIBNeeded;
tmpBitmap:=TBitmap.Create;
tmpBitmap.Assign(tmpjpeg); //执行此步时报错
tmpBitmap.SaveToFile('c:/1.bmp');
fromImage:=TImage.Create(nil);
fromImage.Stretch:=false;
fromImage.AutoSize:=true;
fromImage.Picture.LoadFromFile('c:/1.bmp');
Image1.Picture.Assign(fromImage.Picture);
MemStr.free;
tmpjpeg.Free;
tmpBitmap.Free;
fromImage.Free;
end;
var
fromImage:TImage;
tmpJpeg:TJPEGImage;
tmpBitmap:TBitmap;
MemStr:TMemoryStream;
begin
MemStr:=TMemoryStream.Create;
MemStr.Clear;
MemStr.LoadFromFile('c:/1.jpg');
MemStr.Seek(0,0);
tmpjpeg:=TJPEGImage.Create;
tmpjpeg.LoadFromStream(MemStr);
tmpjpeg.CompressionQuality := 5;
//tmpjpeg.JPEGNeeded;
tmpjpeg.Compress;
//tmpjpeg.DIBNeeded;
tmpBitmap:=TBitmap.Create;
tmpBitmap.Assign(tmpjpeg); //执行此步时报错
tmpBitmap.SaveToFile('c:/1.bmp');
fromImage:=TImage.Create(nil);
fromImage.Stretch:=false;
fromImage.AutoSize:=true;
fromImage.Picture.LoadFromFile('c:/1.bmp');
Image1.Picture.Assign(fromImage.Picture);
MemStr.free;
tmpjpeg.Free;
tmpBitmap.Free;
fromImage.Free;
end;