我用函数function GetPicture(Width,Height:integer):TStream;提取图片时,在出现的对话框里。有部分图片无法预览或是显示模糊不清!其它的正常!仔细检查了图片的属性没有什么特别的,不知道是什么原因让图片在预览时不显示出来!这样的话就没有办法提取图片进DBImage里了。
函数代码如下。
function GetPicture(Width,Height:integer):TStream;
var
OpenDialog:TOpenPictureDialog;
Image:TImage;
jpg:TJpegImage;
bmp:TBitMap;
r:real;
Stream:TMemoryStream;
begin
Stream:=TMemoryStream.Create;
Result:=Stream;
OPenDialog:=TOpenPictureDialog.Create(nil);
try
if OpenDialog.Execute then
begin
Image:=TImage.Create(nil);
Image.AutoSize:=true;
Image.Picture.LoadFromFile(OpenDialog.FileName);
if (image.Width>0) and (Image.Height>0) then
r:=GetIffValue(Width/Image.Width>Height/Image.Height,Height/Image.Height,Width/Image.Width);
Bmp:=TBitMap.Create;
jpg:=TJpegImage.Create;
try
Bmp.Width:=trunc(Image.Width*r);
Bmp.Height:=Trunc(Image.Height*r);
Bmp.Canvas.StretchDraw(Bmp.Canvas.ClipRect,Image.Picture.Graphic);
jpg.Assign(bmp);
//JPG.CompressionQuality:=70;
//JPG.Compress;
jpg.SaveToStream(stream);
result:=Stream;
finally
image.Free;
bmp.Free;
jpg.Free;
end;
end;
finally
OpenDialog.Free;
end;
end;
函数代码如下。
function GetPicture(Width,Height:integer):TStream;
var
OpenDialog:TOpenPictureDialog;
Image:TImage;
jpg:TJpegImage;
bmp:TBitMap;
r:real;
Stream:TMemoryStream;
begin
Stream:=TMemoryStream.Create;
Result:=Stream;
OPenDialog:=TOpenPictureDialog.Create(nil);
try
if OpenDialog.Execute then
begin
Image:=TImage.Create(nil);
Image.AutoSize:=true;
Image.Picture.LoadFromFile(OpenDialog.FileName);
if (image.Width>0) and (Image.Height>0) then
r:=GetIffValue(Width/Image.Width>Height/Image.Height,Height/Image.Height,Width/Image.Width);
Bmp:=TBitMap.Create;
jpg:=TJpegImage.Create;
try
Bmp.Width:=trunc(Image.Width*r);
Bmp.Height:=Trunc(Image.Height*r);
Bmp.Canvas.StretchDraw(Bmp.Canvas.ClipRect,Image.Picture.Graphic);
jpg.Assign(bmp);
//JPG.CompressionQuality:=70;
//JPG.Compress;
jpg.SaveToStream(stream);
result:=Stream;
finally
image.Free;
bmp.Free;
jpg.Free;
end;
end;
finally
OpenDialog.Free;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货