• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipGetImageDecoders

Started by José Roca, June 23, 2008, 10:09:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The following console application uses the GdipGetImageDecoders function to get an array of ImageCodecInfo structures that contain information about the available image decoders.

C++


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

INT main()
{
   // Initialize GDI+.
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR           gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
 
   UINT  num;        // number of image decoders
   UINT  size;       // size, in bytes, of the image decoder array

   ImageCodecInfo* pImageCodecInfo;

   // How many decoders are there?
   // How big (in bytes) is the array of all ImageCodecInfo objects?
   GetImageDecodersSize(&num, &size);

   // Create a buffer large enough to hold the array of ImageCodecInfo
   // objects that will be returned by GetImageDecoders.
   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));

   // GetImageDecoders creates an array of ImageCodecInfo objects
   // and copies that array into a previously allocated buffer.
   // The third argument, imageCodecInfos, is a pointer to that buffer.
   GetImageDecoders(num, size, pImageCodecInfo);

   // Display the graphics file format (MimeType)
   // for each ImageCodecInfo object.
   for(UINT j = 0; j < num; ++j)
   {
      wprintf(L"%s\n", pImageCodecInfo[j].MimeType);   
   }

   free(pImageCodecInfo);
   GdiplusShutdown(gdiplusToken);
   return 0;
}


PowerBASIC


#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"
#INCLUDE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL hr AS LONG
   LOCAL token AS DWORD
   LOCAL StartupInput AS GdiplusStartupInput
   LOCAL numDecoders AS DWORD
   LOCAL nSize AS DWORD
   LOCAL i AS LONG
   LOCAL x AS LONG
   LOCAL p AS BYTE PTR
   LOCAL s AS STRING
   LOCAL nSigCount AS LONG
   LOCAL nSigSize AS LONG

   DIM pImageCodecInfo AS ImageCodecInfo PTR

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

   hr = GdipGetImageDecodersSize(numDecoders, nSize)
   PRINT "Number of decoders: "numDecoders, "Size: "nSize
   REDIM buffer(nSize - 1) AS BYTE
   pImageCodecInfo = VARPTR(buffer(0))
   hr = GdipGetImageDecoders(numDecoders, nSize, BYVAL pImageCodecInfo)

   IF hr = 0 THEN
      FOR i = 1 TO numDecoders
         PRINT "Codec identifier: " GUIDTXT$(@pImageCodecInfo.Clsid)
         PRINT "Format identifier: " GUIDTXT$(@pImageCodecInfo.FormatID)
         PRINT "Codec name: " W2A_(@pImageCodecInfo.CodecName)
         PRINT "Dll name: " W2A_(@pImageCodecInfo.DllName)
         PRINT "Format description: " W2A_(@pImageCodecInfo.FormatDescription)
         PRINT "Filename extension: " W2A_(@pImageCodecInfo.FileNameExtension)
         PRINT "Mime type: " W2A_(@pImageCodecInfo.MimeType)
         PRINT "Flags: " @pImageCodecInfo.Flags
         PRINT "Version: " @pImageCodecInfo.Version
         nSigCount = @pImageCodecInfo.SigCount
         PRINT "Signature count: " nSigCount
         nSigSize = @pImageCodecInfo.SigSize
         PRINT "Signature size: " nSigSize
         p = @pImageCodecInfo.SigPattern
         s = ""
         FOR x = 1 TO nSigCount * nSigSize
            s = s + HEX$(@p) + " "
            INCR p
         NEXT
         PRINT "Signature pattern: " s
         p = @pImageCodecInfo.SigMask
         s = ""
         FOR x = 1 TO nSigCount * nSigSize
            s = s + HEX$(@p) + " "
            INCR p
         NEXT
         PRINT "Signature mask: " s
         INCR pImageCodecInfo       '// Increments pointer
         PRINT "Press any key"
         WAITKEY$
         CLS
      NEXT
   END IF

   GdiplusShutdown token

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