Re: CBitmap to IPIcture.... How?
"Jessica" <Jessica@discussions.microsoft.com> ha scritto nel messaggio
news:AE4B68E0-A47A-46E5-835F-838EB0A9D85D@microsoft.com...
I am having a CBitMap object, and I need to create an IPicture object from
it. The code which I 've written for that is shown below. Can anyone tell
me
whether or not it's correct?
HBITMAP hBmp = (HBITMAP) bmp; // bmp is CBitmap object.
HRESULT hrCreated = E_FAIL;
IPicture* pIPict = NULL;
PICTDESC pictdesc;
pictdesc.bmp.hbitmap = hBmp;
pictdesc.picType = PICTYPE_BITMAP;
pictdesc.cbSizeofstruct = sizeof (PICTDESC);
I would clear pictdesc memory before setting the fields, something like
this:
::ZeroMemory( &pictdesc, sizeof(pictdesc) );
then, as you wrote:
pictdesc.cbSizeOfstruct = ...
...
hrCreated = OleCreatePictureIndirect(&pictdesc,
IID_IPicture,
FALSE,
(void**)&pIPict);
Did you check the return value?
Something like this:
if ( FAILED( hrCreated ) )
... error in OleLoadPictureIndirect
I tried to save the IPicute using the IPictureDisp interface, but the bmp
file created is 0 bytes. Am I missing something here?
You should check the HRESULT return value.
Moreover, did you use IPicture::SaveAsFile to save your bitmap into file?
Moreover, for image management, you may consider interesting to see also the
GDI+ API. It offers also C++ interface to manipulate and load/save images.
HTH,
Giovanni