Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Image.GetPalette method

Applies to: desktop apps only

The Image::GetPalette method gets the ColorPalette of this Image object.

Syntax

Status GetPalette(
  [out]  ColorPalette *palette,
  [in]   INT size
);

Parameters

palette [out]

Type: ColorPalette*

Pointer to a ColorPalette structure that receives the palette.

size [in]

Type: INT

Integer that specifies the size, in bytes, of the palette. Call the Image::GetPaletteSize method to determine the size.

Return value

Type:

Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Examples

The following example creates an Image object based on a BMP file. The image in that file uses 8 bits per pixel. The code calls the Image::GetPaletteSize method of the Image object to determine the size of the image's palette. The call to malloc allocates a buffer large enough to receive the palette, and the call to Image::GetPalette fills that buffer. The code displays the number of colors in the palette ( palette->Count) and then displays the ARGB values of the first five colors in the palette.


#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT main()
{
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   Image* image = new Image(L"Stripes8Bit.bmp");

   UINT size = image->GetPaletteSize();
   printf("The size of the palette is %d bytes.\n", size);
   ColorPalette* palette = (ColorPalette*)malloc(size);

   image->GetPalette(palette, size);

   if(size > 0)
   {
      printf("There are %u colors in the palette.\n", palette->Count);
      printf("The first five colors in the palette are as follows:\n");

      for(INT j = 0; j <= 4; ++j)
         printf("%x\n", palette->Entries[j]);
   }

   delete(image);
   free(palette);
   GdiplusShutdown(gdiplusToken);
   return 0;
}

The preceding code, along with a particular file, Stripes8Bit.bmp, produced the following output:


The size of the palette is 1032 bytes.
There are 256 colors in the palette.
The first five colors in the palette are as follows:
ff000000
ff800000
ff008000
ff808000
ff000080

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusheaders.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Image
Bitmap
Color
ColorPalette
Image::GetPaletteSize
Image::SetPalette
Using Images, Bitmaps, and Metafiles
Images, Bitmaps, and Metafiles

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

Show:
© 2015 Microsoft