Symbian C++ - 从 .mbm 文件加载并显示图像
我有一个 .mbm 文件,我使用 .pkg 文件中的这一行将其复制到我的设备
"$(EPOCROOT)epoc32\data\z\resource\apps\MyApp.mbm" -"!:\resource\apps\MyApp.mbm"
然后在容器的绘图函数中执行此操作。
_LIT(KMBMFile , "\\resource\\apps\\MyApp.mbm" );
CFbsBitmap* iBitmap;
iBitmap->Load(KMBMFile, 0);
gc.BitBlt(Rect().iTl, iBitmap);
但是行 iBitmap->Load(KMBMFile, 0);
引发 KERN-EXEC:0 PANIC
“当内核无法使用指定的对象索引号(原始句柄号)在当前进程或当前线程的对象索引中找到对象时,会引发此恐慌。”
谁能发现我哪里出错了?
谢谢!
I have a .mbm file that I copy to my device using this line in the .pkg file
"$(EPOCROOT)epoc32\data\z\resource\apps\MyApp.mbm" -"!:\resource\apps\MyApp.mbm"
Then in the draw function of my container I do this..
_LIT(KMBMFile , "\\resource\\apps\\MyApp.mbm" );
CFbsBitmap* iBitmap;
iBitmap->Load(KMBMFile, 0);
gc.BitBlt(Rect().iTl, iBitmap);
However the line iBitmap->Load(KMBMFile, 0);
raises a KERN-EXEC:0 PANIC
"This panic is raised when the Kernel cannot find an object in the object index for the current process or current thread using the specified object index number (the raw handle number)."
Can anyone spot where I am going wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在取消引用未初始化的指针,您也可以使用此:
You were dereferencing an uninitialized pointer, you could also use this:
我已经解决了这个问题,因此将在此处发布答案以供将来查看。
使用如下代码段在 MMP 文件中创建 MBM 文件
确保您的 .bmp 图像从 Photoshop 或类似工具保存为 32 位
然后确保您的 MBM 文件在您的 PKG 文件中复制到您的设备
然后在容器的绘制函数中使用如下代码..
这将在屏幕的左上角绘制您的位图(对于背景图像有用)
I have solved this problem so will post answer here for future lookers..
Create an MBM file in your MMP file using a snippet like this
ensure your .bmp images are saved in 32 bit from photoshop or similar
Then sure your MBM file is copied to your device in your PKG file
Then in the draw function of your container use code such as this..
This will draw your bitmap at the top left point of the screen (useful for background image)
CCoeControl::Draw()
代码不应失败,并且当然不应离开(它没有尾随 ..L
)。 在上面的代码片段中,有两个可能会生成错误的调用 -iBitmap
构造函数和iBitmap->Load()
。 位图应该预先分配,而不是在Draw()
中分配 - 如果有一个离开,就会发生不好的事情。另外,按照惯例,只有类成员变量以“i”开头,而上面的
iBitmap
则不是。有关更多详细信息,请参阅 Symbian 编码标准
CCoeControl::Draw()
code should not fail, and should certainly not leave (it has no trailing ..L
). In the code snippet above there are two potentially error-generating calls -iBitmap
constructor andiBitmap->Load()
. The bitmap should be pre-allocated, not allocated inDraw()
- if there is a leave bad things will happen.Also, by convention only class member variables start with 'i', which
iBitmap
above is not.See Symbian Coding Standards for more details
您绝对不应该在 ::Draw 函数中创建 iBitmap,因为它可能会离开。 最好在 CoeControl 的 ConstructL 中执行此操作。 理论上, ::Load 调用可以在 ::Draw 中处理,因为它可能会因多种原因而失败,但并非所有原因都可能是致命的。 不过,您可以在创建控件时轻松地执行此操作,因此最好稍微考虑一下。 我想说,如果控件基本上只是包含位图,那么您应该在 ConstructL 中执行此操作。 如果控件要做很多事情,那么您可能需要在 ::Draw 中处理它。
You should definitely not create iBitmap in the ::Draw function as it could leave. Best to do that in the ConstructL of the CoeControl. Theoretically the ::Load call could be handled in ::Draw as it might fail for a number of reasons, not all of which may be fatal. You could just as easily do this when creating the Control though, so maybe it's best to think about it a little. I would say that if the control is basically just there to contain the bitmap then you should do it in the ConstructL. If there are a number of things that the control does, then you might want to handle it in ::Draw.