• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetImageRawFormat

Started by José Roca, June 23, 2008, 03:49:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates an Image object based on a JPEG file. The code obtains and displays the GUID that identifies the format of the image. Then the code verifies that the image format is JPEG.

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* image = new Image(L"FakePhoto.jpg");
   GUID guid;
   WCHAR strGuid[39];

   // Get the GUID that identifies the image format.
   image->GetRawFormat(&guid);

   // Convert the GUID to a string and display it.
   StringFromGUID2(guid, strGuid, 39);
   wprintf(L"The GUID is %s.\n", strGuid);

   // Was the GUID that identifies the JPEG format retrieved?
   if(guid == ImageFormatJPEG)
      printf("The format is JPEG.\n");
 
   delete image;
   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 pFormat AS GUID

   ' // Initialize GDI+
   StartupInput.GdiplusVersion = 1
   hStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
   IF hStatus THEN
      PRINT "Error initializing GDI+"
      EXIT FUNCTION
   END IF

   strFileName = UCODE$("climber.jpg")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)

   ' // Get the GUID that identifies the image format.
   hStatus = GdipGetImageRawFormat(pImage, pFormat)
   PRINT "The guid is " & GUIDTXT$(pFormat)

   ' // Was the GUID that identifies the JPEG format retrieved?
   IF pFormat = $ImageFormatJPEG THEN PRINT "The format is JPEG."

   ' // Cleanup
   IF pImage THEN GdipDisposeImage(pImage)

   ' // Shutdown GDI+
   GdiplusShutdown token

   WAITKEY$

END FUNCTION
' ========================================================================================