我正在尝试使用下面提到的 dll 函数调整位图图像的大小(缩放)
{ to resize the image }
function ResizeImg(maxWidth,maxHeight: integer;thumbnail : TBitmap): TBitmap;
var
thumbRect : TRect;
begin
thumbRect.Left := 0;
thumbRect.Top := 0;
if thumbnail.Width > maxWidth then
begin
thumbRect.Right := maxWidth;
end
else
begin
thumbRect.Right := thumbnail.Width;;
end;
if thumbnail.Height > maxHeight then
begin
thumbRect.Bottom := maxHeight;
end
else
begin
thumbRect.Bottom := thumbnail.Height;
end;
thumbnail.Canvas.StretchDraw(thumbRect, thumbnail) ;
//resize image
thumbnail.Width := thumbRect.Right;
thumbnail.Height := thumbRect.Bottom;
//display in a TImage control
Result:= thumbnail;
end;
当我使用这个应用程序调用时它工作正常(在我的列表视图中提供所有图像):
//bs:TStream; btmap:TBitmap;
bs := CreateBlobstream(fieldbyname('Picture'),bmRead);
bs.postion := 0;
btmap.Loadfromstream(bs);
ListView1.Items[i].ImageIndex := ImageList1.Add(ResizeImg(60,55,btmap), nil);
但是当我尝试这个应用程序调用(将单个图像放入我的 TImage 组件)时:
bs := CreateBlobstream(fieldbyname('Picture'),bmRead);
bs.postion := 0;
btmap.Loadfromstream(bs);
Image1.Picture.Bitmap := ResizeImg(250,190,btmap);
它给了我一个错误:
thumbnail.Canvas.StretchDraw(thumbRect, thumbnail) ;
说:
AV at address 00350422 in module 'mydll.dll' Read of Address 20000027
当我关闭我的可执行文件时,我得到了这个:
runtime error 216 at 0101C4BA
如果我在我的 exe pas 文件中定义并使用相同的函数 ( ResizeImg
),它可以完全正常工作,没有任何错误。