前几天一直在折腾图片的东西,一直觉得BREW对PNG的支持不是太好,除了显示没有其它什么可操作的了。
其实用IDisplay接口的SetDestination方法是可以方便地实现两种图片的转换,除了速度有点慢而已。
代码并不复杂,如下:
1
IBitmap
*
getBitmapHalf(DisplayWeb
*
pMe,IImage
*
pImage)
2 {
3 IBitmap *pScreen,*pBitmap,*pBitmap2;
4 ITransform *pTransform;
5 AEEImageInfo info;
6
7 IIMAGE_GetInfo(pImage,&info);
8
9 pScreen=IDISPLAY_GetDestination(pMe->pApp->a.m_pIDisplay);
10 if(pScreen)
11 {
12 IBITMAP_CreateCompatibleBitmap(pScreen,&pBitmap,info.cx,info.cy);
13 IBITMAP_CreateCompatibleBitmap(pScreen,&pBitmap2,info.cx,info.cy);
14 if(pBitmap && pBitmap2)
15 {
16 IDISPLAY_SetDestination(pMe->pApp->a.m_pIDisplay,pBitmap);
17 IIMAGE_Draw(pImage,0,0);
18
19 IBITMAP_QueryInterface(pBitmap2,AEECLSID_TRANSFORM,(void*)(ITransform**)&pTransform);
20 if(pTransform)
21 {
22 ITRANSFORM_TransformBltSimple(pTransform,0,0,pBitmap,0,0,info.cx,info.cy,TRANSFORM_SCALE_HALF,COMPOSITE_KEYCOLOR);
23 ITRANSFORM_Release(pTransform);
24 }
25 else
26 IBITMAP_BltIn(pBitmap2,0,0,info.cx/2,info.cy/2,pBitmap,0,0,AEE_RO_COPY);
27
28 IDISPLAY_SetDestination(pMe->pApp->a.m_pIDisplay,NULL);
29
30 IBITMAP_Release(pBitmap);
31
32 }
33 IBITMAP_Release(pScreen);
34 }
35 return pBitmap2;
36}
2 {
3 IBitmap *pScreen,*pBitmap,*pBitmap2;
4 ITransform *pTransform;
5 AEEImageInfo info;
6
7 IIMAGE_GetInfo(pImage,&info);
8
9 pScreen=IDISPLAY_GetDestination(pMe->pApp->a.m_pIDisplay);
10 if(pScreen)
11 {
12 IBITMAP_CreateCompatibleBitmap(pScreen,&pBitmap,info.cx,info.cy);
13 IBITMAP_CreateCompatibleBitmap(pScreen,&pBitmap2,info.cx,info.cy);
14 if(pBitmap && pBitmap2)
15 {
16 IDISPLAY_SetDestination(pMe->pApp->a.m_pIDisplay,pBitmap);
17 IIMAGE_Draw(pImage,0,0);
18
19 IBITMAP_QueryInterface(pBitmap2,AEECLSID_TRANSFORM,(void*)(ITransform**)&pTransform);
20 if(pTransform)
21 {
22 ITRANSFORM_TransformBltSimple(pTransform,0,0,pBitmap,0,0,info.cx,info.cy,TRANSFORM_SCALE_HALF,COMPOSITE_KEYCOLOR);
23 ITRANSFORM_Release(pTransform);
24 }
25 else
26 IBITMAP_BltIn(pBitmap2,0,0,info.cx/2,info.cy/2,pBitmap,0,0,AEE_RO_COPY);
27
28 IDISPLAY_SetDestination(pMe->pApp->a.m_pIDisplay,NULL);
29
30 IBITMAP_Release(pBitmap);
31
32 }
33 IBITMAP_Release(pScreen);
34 }
35 return pBitmap2;
36}
很好理解,就是从屏幕创建两个兼容的Bitmap,然后其中一个作为绘图的目标,将png绘上去,另一个作为转换变形的目标,将前一个(绘有png图的)bitmap用ITransform接口进行变换,返回第二个bitmap即可。