• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetImageType

Started by José Roca, June 23, 2008, 03:58:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates two Image objects: one based on a JPEG file and one based on an Enhanced Metafile (EMF) file. Then the code calls the GdipGetImageType function and verifies that the JPEG file is a bitmap and the EMF file is a metafile.

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"FakePhoto.jpg");
   Image* image2 = new Image(L"SampleMetafile.emf");

   ImageType type1 = image1->GetType();
   ImageType type2 = image2->GetType();

   if(type1 == ImageTypeBitmap)
      printf("The type of image1 is ImageTypeBitmap.\n");

   if(type2 == ImageTypeMetafile)
      printf("The type of image2 is ImageTypeMetafile.\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 pImage1 AS DWORD
   LOCAL pImage2 AS DWORD
   LOCAL strFileName AS STRING
   LOCAL Type1 AS LONG
   LOCAL Type2 AS LONG

   ' // 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), pImage1)

   strFileName = UCODE$("climber.emf")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage2)

   hStatus = GdipGetImageType(pImage1, Type1)
   hStatus = GdipGetImageType(pImage2, Type2)

   IF Type1 = %ImageTypeBitmap THEN PRINT "The type of image1 is ImageTypeBitmap."
   IF Type2 = %ImageTypeMetafile THEN PRINT "The type of image2 is ImageTypeMetafile."

   ' // Cleanup
   IF pImage1 THEN GdipDisposeImage(pImage1)
   IF pImage2 THEN GdipDisposeImage(pImage2)

   ' // Shutdown GDI+
   GdiplusShutdown token

   WAITKEY$

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