德尔福>我可以在我的设备(不是 dfm)中存储位图数据吗?
我在一个单元中声明了一个类,它需要使用特定的位图。 它在我的测试单元的 DFM 中声明如下:
object ImgTop: TImage
Left = 208
Top = 568
Width = 777
Height = 41
Picture.Data = {
0A544A504547496D616765A1CF0000FFD8FFE000104A46494600010101025802
[truncated]
};
但在我的最终单元中,我不会有 dfm。 那么有没有办法可以在我的单位申报呢?
===
谢谢,我现在似乎可以使用它了,对位图的大小限制感到遗憾:( 这就是我所做的:
在我的文件夹中有这些文件:
imgleft.bmp
imgtop.bmp
这是我的资源文件,名为 ScanOCRres.rc:
1 RT_BITMAP "imgtop.bmp"
2 RT_BITMAP "imgleft.bmp"
我已将其设置为使用 C:\Program Files\Borland\Delphi 7\bin\brcc32.exe 自动执行
它生成了该文件
ScanOCRres.RES
在我单位我有 我
{$R *.dfm}
{$R ScanOCRres.RES}
这是我的代码:
var
abmp : TBitmap;
begin
abmp := TBitmap.create;
abmp.LoadFromResourceID(SysInit.HInstance, 1);
abmp.free;
end;
在 LoadFromResourceID 行收到此错误消息:
Project Project1.exe 引发异常类 EAccessViolation,并显示消息“模块 'Project1.exe' 中地址 0040A2C8 处的访问冲突”。 读取地址 00000001'
I have a class declared in a unit, and it needs to work with a specific bitmap.
It is declared in the DFM of my test unit like this:
object ImgTop: TImage
Left = 208
Top = 568
Width = 777
Height = 41
Picture.Data = {
0A544A504547496D616765A1CF0000FFD8FFE000104A46494600010101025802
[truncated]
};
But in my final unit I won't be having a dfm.
So is there a way I can declare it in my unit?
===
Thanks, I seem to have it working now, pitty about the size limitations on bitmaps :(
Here's what I did:
In my folder are these files:
imgleft.bmp
imgtop.bmp
This is my resource file called ScanOCRres.rc:
1 RT_BITMAP "imgtop.bmp"
2 RT_BITMAP "imgleft.bmp"
I have set it to automatically execute with C:\Program Files\Borland\Delphi 7\bin\brcc32.exe
It generated the file
ScanOCRres.RES
In my unit I have
implementation
{$R *.dfm}
{$R ScanOCRres.RES}
And here's my code:
var
abmp : TBitmap;
begin
abmp := TBitmap.create;
abmp.LoadFromResourceID(SysInit.HInstance, 1);
abmp.free;
end;
I get this error message on the LoadFromResourceID line:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0040A2C8 in module 'Project1.exe'. Read of address 00000001'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其放入代码中,但使用起来不太方便。声明一个字节数组并定义图像的每个字节。祝编辑好运。要加载它,我将字节数组包装到
TMemoryStream
中,然后使用LoadFromStream
。更好的方法是将图像存储在资源中。编写一个资源脚本文件,如下所示:
将 .rc 文件添加到您的 Delphi 项目中,它将自动链接到您的程序。在运行时,使用
TBitmap.LoadFromResourceId
< 加载图像/a>:You could put it in your code, but it wouldn't be very convenient to work with. Declare an array of bytes and define each byte of your image. Good luck editing it. To load it, I'd wrap the byte array into a
TMemoryStream
and then useLoadFromStream
.A better way is to store the image in a resource. Write a resource script file like this:
Add that .rc file to your Delphi project, and it will automatically be linked to your program. At run time, load the image with
TBitmap.LoadFromResourceId
:我做了这个。这很粗糙,但很有效。将组件的图片转换为 picture.data 作为字符串。
I made this. It's crude but it works. Converts component's picture to picture.data as a string.