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.GetPaletteSize method

Applies to: desktop apps only

The Image::GetPaletteSize method gets the size, in bytes, of the color palette of this Image object.

Syntax

INT GetPaletteSize();

Parameters

This method has no parameters.

Return value

Type:

Type: INT

This method returns the size, in bytes, of the color palette of this Image object.

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);
   printf("There are %d 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
Using Images, Bitmaps, and Metafiles
Images, Bitmaps, and Metafiles

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

Show: