我正在尝试使用下面提到的
的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
),它可以完全正常运行而没有任何错误。
答案 0 :(得分:3)
除非您采取措施确保这些模块共享相同的运行时和内存分配器,否则无法在模块之间传递Delphi对象。 Ir似乎你没有采取这样的步骤。
基本问题是Delphi对象既是数据又是代码。如果您天真地在另一个模块中创建的对象上调用方法,则可以从该模块中对该模块中的数据执行代码。这通常以运行时错误结束。
您至少有以下选项: