The following console application creates an
Image object. The code gets the pixel format of the
Image object and then compares the obtained value to particular pixel format constants.
C++
#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;
PowerBASIC
#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
LOCAL hStatus AS LONG
LOCAL token AS DWORD
LOCAL StartupInput AS GdiplusStartupInput
LOCAL pImage AS DWORD
LOCAL strFileName AS STRING
LOCAL nFormat AS LONG
LOCAL strFormat AS STRING
' // Initialize GDI+
StartupInput.GdiplusVersion = 1
hStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hStatus THEN
PRINT "Error initializing GDI+"
EXIT FUNCTION
END IF
strFileName = UCODE$("Shapes.jpg")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
hStatus = GdipGetImagePixelFormat(pImage, nFormat)
SELECT CASE AS LONG nFormat
CASE %PixelFormat1bppIndexed : strFormat = "1 bpp indexed"
CASE %PixelFormat4bppIndexed : strFormat = "4 bpp indexed"
CASE %PixelFormat8bppIndexed : strFormat = "8 bpp indexed"
CASE %PixelFormat16bppGrayScale : strFormat = "16 bpp gray scale"
CASE %PixelFormat16bppRGB555 : strFormat = "16 bpp RGB 555"
CASE %PixelFormat16bppRGB565 : strFormat = "16 bpp RGB 565"
CASE %PixelFormat16bppARGB1555 : strFormat = "16 bpp ARGB 1555"
CASE %PixelFormat24bppRGB : strFormat = "24 bpp RGB"
CASE %PixelFormat32bppRGB : strFormat = "32 bpp RGB"
CASE %PixelFormat32bppARGB : strFormat = "32 bpp ARGB"
CASE %PixelFormat32bppPARGB : strFormat = "32 bpp PARGB"
CASE %PixelFormat48bppRGB : strFormat = "48 bpp RGB"
CASE %PixelFormat64bppARGB : strFormat = "64 bpp ARGB"
CASE %PixelFormat64bppPARGB : strFormat = "64 bpp PARGB"
CASE ELSE : strFormat = FORMAT$(nFormat)
END SELECT
PRINT "The pixel format of the image is " & strFormat
' // Cleanup
IF pImage THEN GdipDisposeImage(pImage)
' // Shutdown GDI+
GdiplusShutdown token
WAITKEY$
END FUNCTION
' ========================================================================================