Symbian C++ - 从 .mbm 文件加载并显示图像

发布于 2024-07-10 20:32:50 字数 515 浏览 6 评论 0原文

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

喜爱皱眉﹌ 2024-07-17 20:32:50

您正在取消引用未初始化的指针,您也可以使用此:

// remember to include the EIK environemnt include file
#include <eikenv.h>

_LIT(KMBMFile , "\\resource\\apps\\MyApp.mbm" );
CFbsBitmap* iBitmap;

iBitmap = iEikonEnv->CreateBitmapL( KMBMFile, 0 );
gc.BitBlt( Rect().iTl, iBitmap );

You were dereferencing an uninitialized pointer, you could also use this:

// remember to include the EIK environemnt include file
#include <eikenv.h>

_LIT(KMBMFile , "\\resource\\apps\\MyApp.mbm" );
CFbsBitmap* iBitmap;

iBitmap = iEikonEnv->CreateBitmapL( KMBMFile, 0 );
gc.BitBlt( Rect().iTl, iBitmap );
吾性傲以野 2024-07-17 20:32:50

我已经解决了这个问题,因此将在此处发布答案以供将来查看。

使用如下代码段在 MMP 文件中创建 MBM 文件

START BITMAP    MyApp.mbm
HEADER
TARGETPATH      \resource\apps
SOURCEPATH      ..\gfx
SOURCE          c24 background.bmp
END

确保您的 .bmp 图像从 Photoshop 或类似工具保存为 32 位

然后确保您的 MBM 文件在您的 PKG 文件中复制到您的设备

"$(EPOCROOT)epoc32\data\z\resource\apps\MyApp.mbm" -"!:\resource\apps\MyApp.mbm"

然后在容器的绘制函数中使用如下代码..

_LIT(KMBMFile , "C:\\RESOURCE\\APPS\\MyApp.mbm" );
CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap;
TInt retval = iBitmap->Load(KMBMFile, 0);
gc.BitBlt(Rect().iTl, iBitmap);

这将在屏幕的左上角绘制您的位图(对于背景图像有用)

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

START BITMAP    MyApp.mbm
HEADER
TARGETPATH      \resource\apps
SOURCEPATH      ..\gfx
SOURCE          c24 background.bmp
END

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

"$(EPOCROOT)epoc32\data\z\resource\apps\MyApp.mbm" -"!:\resource\apps\MyApp.mbm"

Then in the draw function of your container use code such as this..

_LIT(KMBMFile , "C:\\RESOURCE\\APPS\\MyApp.mbm" );
CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap;
TInt retval = iBitmap->Load(KMBMFile, 0);
gc.BitBlt(Rect().iTl, iBitmap);

This will draw your bitmap at the top left point of the screen (useful for background image)

烟雨凡馨 2024-07-17 20:32:50

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 and iBitmap->Load(). The bitmap should be pre-allocated, not allocated in Draw() - 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

鱼忆七猫命九 2024-07-17 20:32:50

您绝对不应该在 ::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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文