Re: CBitmap to IPIcture.... How?
"Jessica" <Jessica@discussions.microsoft.com> ha scritto nel messaggio
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
whether or not it's correct?
HBITMAP hBmp = (HBITMAP) bmp; // bmp is CBitmap object.
HRESULT hrCreated = E_FAIL;
IPicture* pIPict = NULL;
pictdesc.bmp.hbitmap = hBmp;
pictdesc.picType = PICTYPE_BITMAP;
pictdesc.cbSizeofstruct = sizeof (PICTDESC);
I would clear pictdesc memory before setting the fields, something like
::ZeroMemory( &pictdesc, sizeof(pictdesc) );
then, as you wrote:
pictdesc.cbSizeOfstruct = ...
hrCreated = OleCreatePictureIndirect(&pictdesc,
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.