Delphi dll图像拉伸错误
我正在尝试使用下面提到的 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
),它工作完全正常,没有任何错误。
I am trying to resize (scale) a bitmap image using a dll function which is below mentioned
{ 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;
It works fine when I use this application call (to feed all the images in my listview):
//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);
But when I try this application call (to get individual image into my TImage component):
bs := CreateBlobstream(fieldbyname('Picture'),bmRead);
bs.postion := 0;
btmap.Loadfromstream(bs);
Image1.Picture.Bitmap := ResizeImg(250,190,btmap);
It gives me an error on:
thumbnail.Canvas.StretchDraw(thumbRect, thumbnail) ;
saying:
AV at address 00350422 in module 'mydll.dll' Read of Address 20000027
And when I close my executable I get this:
runtime error 216 at 0101C4BA
If I define and use the same function (ResizeImg
) inside my exe pas file it works completely fine without any errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您采取措施确保这些模块共享相同的运行时和内存分配器,否则您无法在模块之间传递 Delphi 对象。我看来你还没有采取这样的步骤。
基本问题是 Delphi 对象既是数据又是代码。如果您天真地调用在不同模块中创建的对象上的方法,那么您将对该模块中的数据执行该模块中的代码。这通常会导致运行时错误。
您至少有以下选择:
You can't pass Delphi objects between modules unless you take steps to ensure that those modules share the same runtime and memory allocator. Ir appears you have not taken such steps.
The basic problem is that a Delphi object is both data and code. If you naively call a method on an object that was created in a different module then you execute code from this module on data from that module. That typically ends in runtime errors.
You have at least the following options: