IStream,位图,CBitmap在哪里复制图像数据? [英] IStream, Bitmap, CBitmap where is image data duplicated?
本文介绍了IStream,位图,CBitmap在哪里复制图像数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个指向数据块的指针,它恰好是从jpeg图像文件读取的二进制数据.我为其创建IStream,并从函数中的流中创建位图,如下所示:
Hi,
I have a pointer to a data block which happen to be binary data read from jpeg image file. I create IStream for it, and create bitmap from the stream in my function as following:
.....
IStream* pStream;
DWORD dwresult = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
pStream->Write(pData, (ULONG)nSize, NULL);
// Create bitmap
Bitmap* pBitmap;
pBitmap = Bitmap::FromStream(pStream);
HBITMAP hBitmap = NULL;
pBitmap->GetHBITMAP(Color(0,0,0),&hBitmap);
CBitmap cbitmap;
cbitmap.Attach(hBitmap);
// imgLst is a CImageList
imgList.Add(&cbitmap, RGB(0,0,0));
....
问题是图像数据是否在此函数中的某处重复?
(创建IStream时,创建Bitmap对象时,添加到图像列表时)我想确保没有内存泄漏或过早释放.
在此先感谢
Quy
Question is that whether the image data is duplicate somewhere in this function?
(when create IStream, when create Bitmap object, when add to image list) I want to make sure there is no mem leak or premature release.
Thanks in advance
Quy
推荐答案
嗨Quy,
Gdiplus::Bitmap
对象本身不会产生新数据,它只是相关编解码器和Gdiplus::Image
数据(您的IStream
)的连接器.
成功调用pBitmap->GetHBITMAP(Color(0,0,0),&hBitmap);
时(从IStream
中)读取Gdiplus::Image
数据,并由Gdi32.dll创建Windows位图对象.它返回HBITMAP
.
此时,您可以关闭IStream
并删除HGLOBAL
.
调用imgList.Add(&cbitmap, RGB(0,0,0));
时,ImageList_Add
函数将位图复制到内部数据结构中,并且必须在HBITMAP
上调用::DeleteObject()
.
就您而言,这将在您的cbitmap
对象超出范围时发生.
欢呼声,
AR
Hi Quy,
TheGdiplus::Bitmap
object by itself produces no new data, it is just a connector to the relevant codec and theGdiplus::Image
data (yourIStream
).
When you succesfully callpBitmap->GetHBITMAP(Color(0,0,0),&hBitmap);
theGdiplus::Image
data are read (from yourIStream
) and a Windows bitmap object is created by Gdi32.dll; it''sHBITMAP
is returned.
At that moment you may close theIStream
and delete theHGLOBAL
.
When you callimgList.Add(&cbitmap, RGB(0,0,0));
theImageList_Add
function copies the bitmap to an internal data structure, and you must call::DeleteObject()
on theHBITMAP
.
In your case this will happen when yourcbitmap
object gets out of scope.
cheers,
AR
这篇关于IStream,位图,CBitmap在哪里复制图像数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文