Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21301

GDI + GdipGetImagePixelFormat (untrusted)

$
0
0
Hello, it fails when using an 8-bit image with a transparent palette, return 32 bits, any explanation?


Download the image and put in C:\
Code:

Option Explicit
Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GDIPlusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
Private Declare Sub GdiplusShutdown Lib "gdiplus" (ByVal token As Long)
Private Declare Function GdipGetImagePixelFormat Lib "gdiplus" (ByVal hImage As Long, PixelFormat As Long) As Long
Private Declare Function GdipLoadImageFromFile Lib "GdiPlus.dll" (ByVal mFilename As Long, ByRef mImage As Long) As Long
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal image As Long) As Long

Private Type GDIPlusStartupInput
    GdiPlusVersion          As Long
    DebugEventCallback      As Long
    SuppressBackgroundThread As Long
    SuppressExternalCodecs  As Long
End Type


Public Enum PixelFormat
  PixelFormatUndefined = &H0
  PixelFormat1bppIndexed = &H30101
  PixelFormat4bppIndexed = &H30402
  PixelFormat8bppIndexed = &H30803
  PixelFormat16bppGrayScale = &H101004
  PixelFormat16bppRGB555 = &H21005
  PixelFormat16bppRGB565 = &H21006
  PixelFormat16bppARGB1555 = &H61007
  PixelFormat24bppRGB = &H21808
  PixelFormat32bppRGB = &H22009
  PixelFormat32bppARGB = &H26200A
  PixelFormat32bppPARGB = &HE200B
  PixelFormat48bppRGB = &H10300C
  PixelFormat64bppARGB = &H34400D
  PixelFormat64bppPARGB = &H1A400E
End Enum

Private Sub Form_Load()
    Dim GDIsi As GDIPlusStartupInput
    Dim gToken As Long
    Dim hImage As Long
    Dim Depth As Long
   
    GDIsi.GdiPlusVersion = 1&
    If GdiplusStartup(gToken, GDIsi) = 0 Then
   
        If GdipLoadImageFromFile(StrPtr("C:\folder8bits.png"), hImage) = 0 Then
       
            GdipGetImagePixelFormat hImage, Depth
           
            Debug.Print Depth = PixelFormat32bppARGB
           
            GdipDisposeImage hImage
        End If
        GdiplusShutdown gToken
    End If
   
End Sub

Attached Images
 

Viewing all articles
Browse latest Browse all 21301

Trending Articles