德尔福7->无法从资源文件加载图像
我已经在网上查找了几个小时,使用谷歌,尝试获取 PDF,但仍然无法 在 Delphi 7 中加载图像资源。
我的 test.rc 文件如下所示:
1 RT_BITMAP "1.bmp"
我已使用 Project 将 test.rc 文件添加到我的项目中->添加到项目..,它在构建时编译了 test.res 文件,并且似乎已自动将 .res 文件包含到我的项目中(因为使用 {$R test.res} 会说我已经使用了该资源)。我还尝试使用 Project->Remove from Project.. 从项目中删除 test.res 并手动添加 {$R test.res}< /strong> 我的项目。
但是无论我如何包含 test.res 文件.. 我得到了
项目 Project2.exe 引发异常 带有消息的 EAccessViolation 类 '地址 00408D0C 处发生访问冲突 在模块“Project2.exe”中。读过 地址00000001'。进程停止。 使用“Step”或“Run”继续。
起初我使用了
Image1.Picture.Bitmap.LoadFromResourceID(hInstance,1);
因为这是我使用谷歌找到的。我收到了这个错误。 后来我尝试了
procedure TForm1.Image1Click(Sender: TObject);
var bBitmap : TBitmap;
begin
bBitmap := TBitmap.Create;
try
bBitmap.Handle := LoadBitmap(hInstance, '1');
Image1.Width := bBitmap.Width;
Image1.Height := bBitmap.Height;
Image1.Canvas.Draw(0,0,bBitmap);
finally
bBitmap.Free;
end;
end;
这并没有给我带来任何错误,也没有显示图像,所以问题仍然没有解决。
我是使用资源的新手,但在发布项目之前我必须将一些图像加载到资源中,所以.BMP 文件不会被调和...
任何帮助将不胜感激!
I've been looking hours over the net, using Google, trying for PDF's and still unable
to load an Image resource in Delphi 7..
My test.rc file goes like this:
1 RT_BITMAP "1.bmp"
I've added the test.rc file to my project using Project->Add to Project.. which compiled a test.res file upon build and seems to have automatically included the .res file into my project (because using the {$R test.res} would say I already use that resource). I also tried removing the test.res from the project using Project->Remove from Project.. and manually adding the {$R test.res} to my project.
However no matter how I include the test.res file..
I get the
Project Project2.exe raised exception
class EAccessViolation with message
'Access violation at address 00408D0C
in module 'Project2.exe'. Read of
address 00000001'. Process stopped.
Use Step or Run to continue.
at First I used
Image1.Picture.Bitmap.LoadFromResourceID(hInstance,1);
Because this is what I found using Google. And I got this error.
Later I tried
procedure TForm1.Image1Click(Sender: TObject);
var bBitmap : TBitmap;
begin
bBitmap := TBitmap.Create;
try
bBitmap.Handle := LoadBitmap(hInstance, '1');
Image1.Width := bBitmap.Width;
Image1.Height := bBitmap.Height;
Image1.Canvas.Draw(0,0,bBitmap);
finally
bBitmap.Free;
end;
end;
This didn't get me any errors, and nither did it show the image so the problem remains unsolved..
I'm a newbie to the use of Resources but I must load some images into resources before I release my project so the .BMP files won't be tempered with...
any help would be highly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在测试程序中重现了与您完全相同的问题。
然后我将
RT_BITMAP
更改为BITMAP
,重新编译 RC 并进行测试。有用。
I reproduced exactly your same problem in a test program.
I then changed
RT_BITMAP
toBITMAP
, recompiled RC and tested.It works.