CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 1999

    how to change a 24bit bitmap to a 32bit bitmap using GDI+

    I mean 32bit to 24bit image.


    I have a bitmap file temp.bmp that is a 32bit image, now I want to resave it as 24bit image but for some reason the code below is still saving it as a 32bit image (temp2.bmp) even though 24bit has been specified as the colorDepth.
    Any ideas? do I need to re-render it first? if so, how?

    Status stat;
    Image* image = new Image(_T("temp.bmp"));

    Gdiplus::EncoderParameters EncoderParameters1;
    ULONG colorDeph = 24;
    EncoderParameters1.Count = 1;
    EncoderParameters1.Parameter[0].Guid = EncoderColorDepth;
    EncoderParameters1.Parameter[0].Type = EncoderParameterValueTypeLong;
    EncoderParameters1.Parameter[0].NumberOfValues = 1;
    EncoderParameters1.Parameter[0].Value = &colorDeph;

    CLSID m_clsidGdiplusBmpEncoder;
    GetEncoderClsid( L"image/bmp", &m_clsidGdiplusBmpEncoder );
    stat = image->Save( _T("temp2.bmp"), &m_clsidGdiplusBmpEncoder, &EncoderParameters1 );

    Last edited by hobnob; January 16th, 2014 at 07:31 AM.

  2. #2
    Join Date
    Dec 1999

    Re: how to change a 24bit bitmap to a 32bit bitmap using GDI+

    worked it out, draw it in memory to 24bit then save.

    Image* image = new Image(L"temp.bmp"); // 32bit image

    Bitmap *dest = new Bitmap(image->GetWidth(), image->GetHeight(), PixelFormat24bppRGB);

    //create a graphics from the image
    Graphics *g = Graphics::FromImage(dest);

    //draw the 32bit per pixel image into the 24 bit per pixel image
    g->DrawImage(image, Point(0, 0));

    delete image; // source

    //now save the 24 bit per pixel to disk
    CLSID m_clsidGdiplusBmpEncoder;
    GetEncoderClsid( L"image/bmp", &m_clsidGdiplusBmpEncoder );
    dest->Save( L"temp2.bmp", &m_clsidGdiplusBmpEncoder, NULL );

    delete dest;
    delete g;

  3. #3
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: how to change a 24bit bitmap to a 32bit bitmap using GDI+

    the GDI plus bmp encoder doesn't support 24bpp. (I'm not entirely sure, but I even think it doesn't even support this parameter at all).
    this is similar to trying to set a JPEG encoder to 32bpp (or something other than 24), JPEG doesn't support an alpha channel, so encoding is Always 24bpp

  4. #4

    Re: how to change a 24bit bitmap to a 32bit bitmap using GDI+

    I tend to join to your opinion. I haven't heard about such support.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.