Re: Transform a bitmap depth

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 2 May 2005 11:02:46 +0900, "William" <port@xxxxxxxxxxxxxxxxxx>
wrote:

>William
>
>> If the image you obtain is 15-32 bit, you do not need to create a
>> palette unless you have a need to display it on a 256-color system.
>> But if you require an 8-bit indexed-color DIB from a higher-depth
>> image, you will have to create it yourself, using any of many known
>> quantization methods (median cut, popularity, fixed distribution,
>> grayscale, Windows standard etc) and dithering methods
>> (Floyd-Steinberg, Stucki, Burkes, etc.). Google and
>> sci.image.processing will be your friends for these.
>> But if the clipboard image is already 8-bpp DDB, there should also be
>> a palette available that you can use directly. (Availability of an
>> 8-bit CF_BITMAP should imply the simultaneous availability of a
>> CF_PALETTE).

>My application need to load, display, save, and deal with 8bit bitmap only,
>no matter what Windows video settings is. Also, if an user copies a bitmap
>from other applications, for example, MSPaint.exe, my application have to
>transform it into 8bit bitmap format before displaying and/or save it.
>
>I know that transforming DDB(clipboard)->DIB(8bit)->DDB(8bit) is one of the
>methods. However, I want to know the normal method to transform it. You said
>that creating an optimized palette is a way. But I still don't know where to
>start? Could you show me a sample source. That will be helpful.

My own color quantization (picking the colors for the 8-bit indexed
image) and dithering routines are dependent on too much other code to
tweeze out easily.

For a simple conversion to the Windows halftone palette, you could use
CreateHalftonePalette() to obtain 256 generally useful colors, which
you will have to transfer to the bmiColors[] array for your 8-bit DIB
before, then convert the clipboard DIB to your DIB. However, the
quality is going to vary significantly depending on the source bitmap.

Another option would be to always generate grayscale DIBs, simply by
averaging each pixels red, green and blue values.

If you need higher quality results, news://sci.image.processing can
probably recommend some simple and cheap libraries for doing this, and
GDI+ probably also has the ability.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
.



Relevant Pages

  • Re: LoadImage & LR_CREATEDIBSECTION
    ... > and is assumed to use the system palette. ... transform a DDB into a DIB. ... height, colordepth, colors and the bitmap), what is supposed to be wrong ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Image from memory
    ... > residing in memory. ... I would like to display it in a picture or image ... It depends on what format your DIB is, and what exactly you want to do with it. ... Alternatively if you wish to use it with the OLE StdPicture object then you can wrap the Bitmap using my OLEPicture ...
    (microsoft.public.vb.general.discussion)
  • Re: Transform a bitmap depth
    ... My application need to load, display, save, and deal with 8bit bitmap only, ... no matter what Windows video settings is. ... > palette unless you have a need to display it on a 256-color system. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Creating a GDI+ Bitmap from an 8-bit Bitmap
    ... You could also try calling UnrealizeObject before creating your gdi+ bitmap. ... This will force the system to completely remap the logical palette to the ... I am trying to capture a portion of the screen, and then display that ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Creating a GDI+ Bitmap from an 8-bit Bitmap
    ... Ok, when I create the GDI+ bitmap from a DIB, the image looks a bit better. ... That tells me that something is still a bit off with my palette. ...
    (microsoft.public.win32.programmer.gdi)