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

Applies to: desktop apps only

The Image::GetPixelFormat method gets the pixel format of this Image object.

Syntax

PixelFormat GetPixelFormat();

Parameters

This method has no parameters.

Return value

Type:

Type: PixelFormat

This method returns an integer that indicates the pixel format of this Image object. The PixelFormat data type and constants that represent various pixel formats are defined in Gdipluspixelformats.h. For more information about pixel format constants, see Image Pixel Format Constants.

Examples

The following console application creates two Image objects: one based on a PNG file and the other based on a BMP file. The code gets the pixel format of each Image object and then compares the obtained values to particular pixel format constants.


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

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

   Image* image1 = new Image(L"Mosaic.png");
   Image* image2 = new Image(L"Stripes8Bit.bmp");

   PixelFormat pixelFormat1 = image1->GetPixelFormat();
   PixelFormat pixelFormat2 = image2->GetPixelFormat();
 
   if(pixelFormat1 == PixelFormat24bppRGB)
      printf("The pixel format of image 1 is 24bppRGB.\n");

   if(pixelFormat2 == PixelFormat8bppIndexed)
      printf("The pixel format of image 2 is 8bppIndexed.\n");

   delete image1;
   delete image2;
   GdiplusShutdown(gdiplusToken);
   return 0;

The preceding code, along with two particular files, Mosaic.png and Stripes8Bit.bmp, produced the following output:


The pixel format of image 1 is 24bppRGB.
The pixel format of image 2 is 8bppIndexed.
}

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
Image Pixel Format Constants
Using Images, Bitmaps, and Metafiles
Types of Bitmaps

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

Show:
© 2014 Microsoft