这是我第一篇文章。我有个问题。 我需要拍摄一个桌面的sceenshot,将其转换为jpeg,将其存储在缓冲区中,然后对其进行处理并通过互联网发送。从内存中获取jpeg的大小(使用GDI ++转换)
我已经用GetDC ....和GDI +编写了用于将HBITMAP转换为jpeg的代码。我现在遇到的问题是我不知道已经保存到IStream中的jpeg的大小。以下是将HBITMAP hBackBitmap引用的位图转换为jpeg并将其保存到pStream中的代码的一部分。我需要知道有多少字节被写入pStream,我怎么能使用pStream(获得PVOID手柄):
Gdiplus::Bitmap bitmap(hBackBitmap, NULL);///loading the HBITMAP
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED, nBlockSize) ;//allocating memory, the size of the current bitmap size. i'm over allocating but i don't think there is any way to get the exact ammount I need to allocate, is there?
if(!hGlobal)
return;
IStream* pStream = NULL ;
if(CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) != S_OK)
return;
bitmap.Save(pStream, &clsid);
我需要的是:1。 找出JPEG的大小,多少字节已经写入流中 2.如何使用流。例如,我可以为流中的数据获取PVOID吗?
谢谢。
谢谢。 这是一个很好的解决方案,因为我不需要为流分配额外的内存。 – Nemok 2009-07-07 10:26:50