如何复制位图句柄
来源:互联网 发布:品牌策划案例 知乎 编辑:程序博客网 时间:2024/05/16 06:21
Using the Handle() and Duplicate() methods of the CFbsBitmap class we can easily duplicate a bitmap object.
The resulting object points to the same bitmap object but can be independently deleted from the original object.
This is due to the fact that CFbsBitmap is really a handle to a Bitmap managed by font and bitmap server.
The managed Bitmap object is reference counted and only deleted when reference count reaches zero.
So when handle to the Bitmap is duplicated the resulting CFbsBitmap object refereces the same bitmap,
only with its reference count incremented.
使用CFbsBitmap类的Handle()和Duplicate方法,我们可以容易的复制一个位图对象。复制的对象指向和源相同的位图对象,但是可以被单独的从原始对象删除。
这是因为实际上CFbsBitmap是字体位图服务器所管理的一个位图句柄。被管理的位图对象是被引用计数的。
只有当引用计数达到0时才被删除。所以当位图的句柄被复制时,结果是CFbsBitmap对象指向相同的位图,仅仅是引用计数增长了。
Usage Scenarios
1. Use these API to share CFbsBitmap instances across threads/processes as you cannot share instances of CFbsBitmap directly between threads.
2. An object can take an independent ownership a CFbsBitmap instances contained by another object without fearing deletion by the containing object.
3. You can also use this technique for making a copy of the bitmap( in the same thread) rather than copying them pixel by pixel for quick,temporary usage.
使用场合:
1。线程进程间共享位图实例,因为你不能直接在线程间共享位图实例。
2。一个对象可以得到一个位图实例的独立所有权,而不害怕删除其中包含的对象。
3。你可以使用这个技术拷贝一个位图(相同线程中),而不是按像素来拷贝,为了效率,但临时使用。
Code Snippet
The following code snippet demonstrates duplicating bitmap handles within a single thread.
//Duplicates a bitmap creating and returning a new CFbsBitmap object.
//Ownership of newly created object vest with the caller.
CFbsBitmap* DuplicateBitmapL(CFbsBitmap & aSourceBitmap)
{
//Target bitmap.
CFbsBitmap* dstbitmap = new (ELeave) CFbsBitmap;
CleanupStack::PushL(dstbitmap);
//Get the handle to source bitmap
TInt srchandle=aSourceBitmap.Handle();
//Duplicate the bitmap handle. Increases the RefCount of bitmap
//managed but Fbs Server
User::LeaveIfError(dstbitmap->Duplicate(srchandle));
//It should be better to track the error returned by Duplicate()
//to get the notification about whether the bitmap is copied successfully or not.
CleanupStack::Pop(dstbitmap);
return dstbitmap;
}
Code Snippet
The following code snippet demonstrates duplicating CGulIcon.
CGulIcon* DuplicateBitmapL(CGulIcon& aIcon)
{
CFbsBitmap* pBitmap = new (ELeave) CFbsBitmap();
CleanupStack::PushL(pBitmap);
CFbsBitmap* pBitMask = new (ELeave) CFbsBitmap();
CleanupStack::PushL(pBitMask);
User::LeaveIfError(pBitmap->Duplicate(aIcon.Bitmap()->Handle()));
User::LeaveIfError(pBitMask->Duplicate(aIcon.Mask()->Handle()));
CGulIcon* Icon = CGulIcon::NewL(pBitmap, pBitMask);
//Both pBitmap and pBitMask are now owned by Icon
CleanupStack::Pop(2);
return Icon ;
}
NOTE: This way we are not copying the bitmap to another, we are just creating a (duplicate) handle for the bitmap, in the font and bitmap server.
Also, deleting one bitmap (thus handle) does not affect the other one.
- 如何复制位图句柄
- 位图复制
- 获取位图资源句柄
- 从位图数据取得位图句柄
- HBITMAP位图句柄转换图像
- 得到HBITMAP句柄保存位图
- 复制对象句柄
- 复制位图到剪贴板
- android 大位图复制
- android 大位图复制
- 如何得到句柄、窗口句柄
- 将位图句柄保存为BMP文件
- 由像素数据构造 位图句柄..
- MFC下获得位图句柄的方法
- 将位图句柄写到文件
- DuplicateHandle复制句柄保护文件
- 3.3.5 复制对象句柄
- 复制文件句柄dup2 函数
- a:hover伪类在IE6下的问题
- 艾宾浩斯记忆曲线
- grep用法
- SVN 管理多个项目
- js方法大全
- 如何复制位图句柄
- 笔试面试之1--n之间1出现的个数
- oracle 分析函数 之 rollup,cube
- NOKIA论坛 how to symbian C++
- 世界杯期间免费解决网站问题
- Linux下GCC编程四个过程
- mysql_pconnect -- PHP打开一个到 MySQL 服务器的持久连接
- jquery 写的坦克大战。。。
- 教你如何解除试用版软件的期限