Symbian学习笔记(4):在GUI应用中使用图像
2010-02-22 10:47
561 查看
http://blog.csdn.net/sharetop/archive/2008/03/13/2179536.aspx
要在应用程序中增加图像图标资源,过程如下:
第一步,先将要加入的图像放在工程的/gfx目录下,如:
qgn_menu_DemoUI.svg
splash2.bmp
前面一个就是应用程序图标(可以修改它)。
第二步,修改/group目录下的Icons_scalable_dc.mk文件,不知道为什么,工程向导生成的这个文件相当不完整,郁闷。
TARGETDIR=$(ZDIR)/resource/apps
ICONTARGETFILENAME=$(TARGETDIR)/DemoUI_0xE8656D58.mif
HEADERDIR=C:/Symbian/workspace/DemoUI/inc
HEADERFILENAME=$(HEADERDIR)/DemoUI.mbg
上面的targetdir是原有的,下面的headerdir是我加上的,因为我需要一个mbg文件(以前旧方式也有这个头文件)。
RESOURCE :
mifconv $(ICONTARGETFILENAME) /h$(HEADERFILENAME) /
/c32,8 $(ICONDIR)/qgn_menu_DemoUI.svg /
/c24 $(ICONDIR)/splash2.bmp
RELEASABLES :
@echo $(HEADERFILENAME)&& /
@echo $(ICONTARGETFILENAME)
主要是那个mifconv的参数,加上/h生成mbg头文件,注意这里的/c32,8 表示我们只提供一个svg文件但是将它的8bit图像作为它的mask,比
原来的方式简单多了,当然你也可以新做一个图像作为mask。
[补充@2008-03-14]
昨天这个例子只在模拟器上成功了,真机失败,无法加载bmp图像。
后来出编译时的控制台输出发现,它只把svg图片放在mif文件中,而bmp图片仍会放入一个同名的mbm文件中。所以我们还得修改pkg文件,让mbm也打包进sisx中:
"$(EPOCROOT)Epoc32/data/z/resource/apps/DemoUI_0xE8656D58.mif" -"!:/resource/apps/DemoUI_0xE8656D58.mif"
"$(EPOCROOT)Epoc32/data/z/resource/apps/DemoUI_0xE8656D58.mbm" -"!:/resource/apps/DemoUI_0xE8656D58.mbm"
而代码中则无所谓了,因为AknIconUtils::CreateIconL()会自动判断是去mif还是mbm中读取图像资源。
第三步,先把上面的改完后,编译一下,就能得到mif文件和mbg文件了。
下面在container中显示这个图像splash2.bmp,先修改.h文件,增加两个CFbsBitmap。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CFbsBitmap* iBkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CFbsBitmap* iBkImageMask;
修改cpp文件,如此加载和显示:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
_LIT(KMbmFileName,"/resource/apps/DemoUI_0xE8656D58.mif");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
const TInt KMyIconMaxWidth(100);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
const TInt KMyIconMaxHeight(100);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CDemoUIAppView::ConstructL( const TRect& aRect )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TFileName fullname(KMbmFileName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CompleteWithAppPath(fullname);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iBkImage=AknIconUtils::CreateIconL(fullname,EMbmDemouiSplash);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CDemoUIAppView::Draw( const TRect& aRect ) const
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CWindowGc& gc = SystemGc();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TRect drawRect( Rect());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
gc.Clear( drawRect );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
gc.BitBlt(TPoint(0,0),iBkImage);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
其实这里与旧方式差不多了,但是原来的那个iBkImage->Load()方法已经不管用了,只能用AknIconUtils提供的这个方法CreateIconL。
另外,如果是加载SVG呢,其实也一样的,如果同时加载mask呢?也一样。例如:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AknIconUtils::CreateIconL(iBkImage, iBkImageMask, fullname, EMbmDemouiQgn_app_demoui, EMbmDemouiQgn_menu_demoui_mask);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AknIconUtils::SetSize(iBkImage, TSize(KMyIconMaxWidth, KMyIconMaxHeight));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AknIconUtils::SetSize(iBkImageMask, TSize(KMyIconMaxWidth, KMyIconMaxHeight));
显示时就这样:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
TPoint point = TPoint(aRect.Center().iX - (KMyIconMaxWidth/2),aRect.Center().iY - (KMyIconMaxHeight/2));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
gc.BitBltMasked(point, iBkImage, aRect, iBkImageMask, EFalse);
今天找了找SVG的编辑器,觉得那个RealDraw还行。
[补充@2008-03-20]
关于SVG格式的显示问题,需要补充两点:
1、它必须要设置尺寸才可以正确显示,虽然我们在制作SVG时给了画布尺寸在SVG文件中也有尺寸信息,但是如果代码中不调用AknIconUtils::SetSize,则无法显示,不报错就是不显示,很BT的问题。
2、关于Mask的问题,因为SVG不是透明的(在制作SVG时画布颜色可以选白色),可以用MASK来制作透明效果,也就是白色部分作为透明色的话则BitBltMasked函数最后一个参数为EFalse,否则如以黑色为透明它应该是ETrue。
如果需要Mask,别忘了在mk文件中这样:/c32,8 表示原图是32位而用它的8位图作为mask图像。
今天学习一下如何修改GUI程序中的图标与如何加载图像。
与2nd.不同的是,3rd.支持svg格式的可缩放图标(最大好处在于一个图标搞定,以前用bmp时为了应用程序的菜单图标得要做四个小图标)。而且,现在有了一种新的图像打包格式mif(这名字咋跟BREW中那个MIF一样啊)。虽然还支持以前的MBM方式但是不建议使用了。要在应用程序中增加图像图标资源,过程如下:
第一步,先将要加入的图像放在工程的/gfx目录下,如:
qgn_menu_DemoUI.svg
splash2.bmp
前面一个就是应用程序图标(可以修改它)。
第二步,修改/group目录下的Icons_scalable_dc.mk文件,不知道为什么,工程向导生成的这个文件相当不完整,郁闷。
TARGETDIR=$(ZDIR)/resource/apps
ICONTARGETFILENAME=$(TARGETDIR)/DemoUI_0xE8656D58.mif
HEADERDIR=C:/Symbian/workspace/DemoUI/inc
HEADERFILENAME=$(HEADERDIR)/DemoUI.mbg
上面的targetdir是原有的,下面的headerdir是我加上的,因为我需要一个mbg文件(以前旧方式也有这个头文件)。
RESOURCE :
mifconv $(ICONTARGETFILENAME) /h$(HEADERFILENAME) /
/c32,8 $(ICONDIR)/qgn_menu_DemoUI.svg /
/c24 $(ICONDIR)/splash2.bmp
RELEASABLES :
@echo $(HEADERFILENAME)&& /
@echo $(ICONTARGETFILENAME)
主要是那个mifconv的参数,加上/h生成mbg头文件,注意这里的/c32,8 表示我们只提供一个svg文件但是将它的8bit图像作为它的mask,比
原来的方式简单多了,当然你也可以新做一个图像作为mask。
[补充@2008-03-14]
昨天这个例子只在模拟器上成功了,真机失败,无法加载bmp图像。
后来出编译时的控制台输出发现,它只把svg图片放在mif文件中,而bmp图片仍会放入一个同名的mbm文件中。所以我们还得修改pkg文件,让mbm也打包进sisx中:
"$(EPOCROOT)Epoc32/data/z/resource/apps/DemoUI_0xE8656D58.mif" -"!:/resource/apps/DemoUI_0xE8656D58.mif"
"$(EPOCROOT)Epoc32/data/z/resource/apps/DemoUI_0xE8656D58.mbm" -"!:/resource/apps/DemoUI_0xE8656D58.mbm"
而代码中则无所谓了,因为AknIconUtils::CreateIconL()会自动判断是去mif还是mbm中读取图像资源。
第三步,先把上面的改完后,编译一下,就能得到mif文件和mbg文件了。
下面在container中显示这个图像splash2.bmp,先修改.h文件,增加两个CFbsBitmap。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CFbsBitmap* iBkImage;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CFbsBitmap* iBkImageMask;
修改cpp文件,如此加载和显示:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
_LIT(KMbmFileName,"/resource/apps/DemoUI_0xE8656D58.mif");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
const TInt KMyIconMaxWidth(100);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
const TInt KMyIconMaxHeight(100);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CDemoUIAppView::ConstructL( const TRect& aRect )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TFileName fullname(KMbmFileName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CompleteWithAppPath(fullname);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iBkImage=AknIconUtils::CreateIconL(fullname,EMbmDemouiSplash);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CDemoUIAppView::Draw( const TRect& aRect ) const
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CWindowGc& gc = SystemGc();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TRect drawRect( Rect());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
gc.Clear( drawRect );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
gc.BitBlt(TPoint(0,0),iBkImage);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
其实这里与旧方式差不多了,但是原来的那个iBkImage->Load()方法已经不管用了,只能用AknIconUtils提供的这个方法CreateIconL。
另外,如果是加载SVG呢,其实也一样的,如果同时加载mask呢?也一样。例如:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AknIconUtils::CreateIconL(iBkImage, iBkImageMask, fullname, EMbmDemouiQgn_app_demoui, EMbmDemouiQgn_menu_demoui_mask);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AknIconUtils::SetSize(iBkImage, TSize(KMyIconMaxWidth, KMyIconMaxHeight));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AknIconUtils::SetSize(iBkImageMask, TSize(KMyIconMaxWidth, KMyIconMaxHeight));
显示时就这样:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
TPoint point = TPoint(aRect.Center().iX - (KMyIconMaxWidth/2),aRect.Center().iY - (KMyIconMaxHeight/2));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
gc.BitBltMasked(point, iBkImage, aRect, iBkImageMask, EFalse);
今天找了找SVG的编辑器,觉得那个RealDraw还行。
[补充@2008-03-20]
关于SVG格式的显示问题,需要补充两点:
1、它必须要设置尺寸才可以正确显示,虽然我们在制作SVG时给了画布尺寸在SVG文件中也有尺寸信息,但是如果代码中不调用AknIconUtils::SetSize,则无法显示,不报错就是不显示,很BT的问题。
2、关于Mask的问题,因为SVG不是透明的(在制作SVG时画布颜色可以选白色),可以用MASK来制作透明效果,也就是白色部分作为透明色的话则BitBltMasked函数最后一个参数为EFalse,否则如以黑色为透明它应该是ETrue。
如果需要Mask,别忘了在mk文件中这样:/c32,8 表示原图是32位而用它的8位图作为mask图像。
相关文章推荐
- Symbian学习笔记(4):在GUI应用中使用图像
- Symbian学习笔记(4):在GUI应用中使用图像
- Symbian学习笔记(4)——在GUI应用中使用图像
- Symbian学习笔记(4)——在GUI应用中使用图像
- 【Oencv2计算机视觉学习笔记(二)】使用Qt创建GUI应用
- 使用 Spring Boot 快速构建 Spring 框架应用---学习笔记
- 微软企业库4.1学习笔记(二十二)加解密模块2 在应用中使用加密解密
- 《Excel 2010 SQL完全应用》学习笔记之一:SQL常见函数的使用
- Xcode学习笔记---如何使用Xcode中的storyboard构建你的第一个IOS应用
- OpenCv学习笔记(八)---细说HighGUI(图像用户界面)之滑动条createTrackbar()详解
- 瓦片地图学习笔记一 编辑器使用及地图添加,对象层应用
- MVC使用Spring.Net应用IOC(依赖倒置)学习笔记3
- Android应用开发学习笔记之使用Bundle交换数据
- glib学习笔记三(续)——GLib核心应用支持:在Linux下使用IO通道(IO Channels)
- opencv学习笔记第五章 使用形态学滤波对图像进行开闭运算
- 我的OpenCV学习笔记(18):使用Sobel变化和拉普拉斯变换检测图像边沿
- Symbian学习笔记(10):使用ListBox
- java学习笔记图形程序设计及GUI应用小结(1)
- HTML学习笔记[3]使用图像
- java学习笔记图形程序设计及GUI应用小结(3)