dimanche 3 juillet 2016

Saving an RGB CImage


I've attempting to save a RGB CImage, however it keeps returning E_FAIL. If the CImage was internaly 32-bits(RGBA) rather than 24-bits(RGB), the image saves just fine.

Here's some relevant code:

auto bitmapstream = new unsigned char[bufferSize];
memcpy(bitmapstream, *imagedata, bufferSize);

CBitmap bmp;
bmp.CreateBitmap(width, height, 1, 24, bitmapstream);
CImage img;
img.Attach(bmp);

auto res = img.Save(LR"(C:Usersp91771Desktoptestimage.bmp)");

And when I step into img.Save, this is what I am getting (atlimage.h):

Gdiplus::Bitmap bm( m_hBitmap, NULL );
status = bm.Save( pwszFileName, &clsidEncoder, NULL );
if( status != Gdiplus::Ok )
{
    return( E_FAIL );
}

The status code it returns is Invalid Parameter(2), so I am guessing that &clsidEncoder is somehow invalid. However, this is something that CImage::Save generates internally. Is there something I need to do to specify the correct Encoder?


Aucun commentaire:

Enregistrer un commentaire