VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "c32bppDIB"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

' Credits/Acknowledgements - Thanx goes to:
'   Paul Caton for his class on calling non VB-Friendly DLLs that use _cdecl calling convention
'       Used when calling non VB-friendly zLIB dll versions
'   Alfred Koppold for his PNG, VB-only, decompression routines.
'       Used when zLib & GDI+ not available
'   Carles P.V for his pvResize logic
'       Used when manually scaling images with NearestNeighbor or BiLinear interpolation
'   www.zlib.net for their free zLIB.dll, the standard DLL for compressing/decompressing PNGs
'       Without it, we'd be limited to GDI+ for creating PNGs
'   coders like you that provide constructive criticism to make this class better & more all-inclusive
'       Without your comments, this project probably would have died several versions/updates ago
' For most current updates/enhancements visit the following:
'   Visit http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=67466&lngWId=1
' To see a usercontrol applying a version of this class
'   AlphaImage Control. http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=68262&lngWId=1
'   Image List Control. http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=69621&lngWId=1

' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'                                    O V E R V I E W
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
' AlphaBlend API :: (msimg32.dll) , GDI+ API (gdiplus.dll)

' About 32bpp pre-multiplied RGB (pARGB) bitmaps, if you are not aware.
'   - These are used specifically for the AlphaBlend API & are GDI+ compatible
'   Advantages:
'       - Images can be per-pixel alpha blended
'       - Opacity can be simultaneously adjusted during rendering
'       - AlphaBlend does both BitBlt & StretchBlt for pARGB images.
'       - Speed: AlphaBlend & GDI+ are pretty quick APIs vs manual blending
'   Disadvantages:
'       - The original RGB values are permanently destroyed during pre-multiplying
'           -- Premultiplied formula: preMultipliedRed=(OriginalRed * Alpha) \ 255
'           -- There is no way to convert pARGB back to non-premultiplied RGB values
'              The formula would be: reconstructedRed=(preMultipliedRed * 255) \ Alpha.
'               but because of integer division when pre-multiplying, the result is very
'               close and if this should be premultiplied again & converted again, the
'               calculated colors can eventually be completely different than the original.
'               Fully opaque pixels & fully transparent pixels are not affected.
'           ** Note: When images are converted to PNG formats, removal of
'              premultiplication is performed to meet PNG specs.
'       - Displaying a pre-multiplied bitmap without AlphaBlend/GDI+ will not result in
'           the image being displayed as expected.
'       - Not ideal for saving due to its size: SizeOf= W x H x 4
'           -- better to save source image instead or compress the DIB bytes using favorite compression utility
'           -- with GDI+ or zLib, image can be converted to PNG for storage
'       - AlphaBlend API is not included/compatible with Win95, NT4 and lower
'       - AlphaBlend on Win9x systems can be buggy, especially when rendering to DIBs vs DDBs
' Note that GDI+ is standard on WinXP+, and can be used on Win98,ME,2K & on NT4 if SP6 is installed
' Download GDI+ from:
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlus.asp
' Download ZLib from: http://www.zlib.net

' ----------------------------------------------
' About Win95, Win98, WinME, NT3.5 & NT4 support
' ----------------------------------------------
' These routines may not honor AlphaBlend if it exists on those systems. Win98's version,
' for example, has several bugs that can crash the application when AlphaBlending to DIBs.
' NT4, NT3.5 & Win95 do not come with AlphaBlend and I do not have WinME to test with.
' Therefore, to support these older systems, the Render routine will alphablend manually
' regardless if the AlhpaBlend API exists on the older system or not. However, this can
' be overridden by you. See isAlphaBlendFriendly routine. Therefore, AlphaBlend is only
' reliable on Win2K and above. XP & above already have GDI+


' Class Purpose:
' ----------------------------------------------
' This class holds the 32bpp image. It also marshals any new image thru
' the battery of parsers to determine best method for converting the image
' to a 32bpp alpha-compatible image. It handles rendering, rotating, scaling,
' mirroring of DIBs using manual processes, AlphaBlend, and/or GDI+.

' The parser order is very important for fastest/best results...
' cPNGparser :: will convert PNG, all bit depths; aborts quickly if not PNG
' cGIFparser :: will convert non-transparent/transparent GIFs; aborts quickly
' cICOpraser :: will convert XP-Alpha, paletted, true color, & Vista PNG icons
'               -- can also convert most non-animated cursors
' cBMPparser :: will convert bitmaps, wmf/emf & jpgs

' As a last resort, when GDI+ exists, anything unable to be processed by the
' parsers (i.e., TIFFs) are sent to GDI+. If GDI+ can process the image, then
' the image will be converted, internally, to PNG to enable additional processing.

' The parsers are efficient. Most image formats have a magic number that give
'   a hint to what type of image the file/stream is. However, checks need to
'   be employed because non-image files could feasibly have those same magic
'   numbers. If the image is determined not to be one the parser is designed
'   to handle, the parser rejects it and the next parser takes over.  The
'   icon parser is slightly different because PNG files can be included into
'   a Vista ico file. When this occurs, the icon parser will pass off the
'   PNG format to the PNG parser automatically.
' And last but not least, the parsers have no advanced knowledge of the image
' format; as far as they are concerned, anything passed is just a byte array

' Class Organization:
' ----------------------------------------------
' Search the class for the words NEW SECTION
' The class routines are organized in the following sections:
'   Class Initialization & Termination Routines
'   Public Properties & Methods (almost 60 and growing)
'       Public Read-Only Properties
'       Public Methods
'       Class to Class Communication Methods
'   Local Support Functions
' ----------------------------------------------

' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'                                       CHANGE HISTORY
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
' Accompanying FAQ.rtf is updated with every change
' Last changed: 18 Nov 07. See change history within the FAQ file
' 26 Dec 06: First version
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

' No APIs are declared public. This is to prevent possibly, differently
' declared APIs, or different versions of the same API, from conflicting
' with any APIs you declared in your project. Same rule for UDTs.
' Note: I did take liberties, changing parameter types, in several APIs throughout

' Used to determine operating system
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As Any) As Long
Private Type OSVERSIONINFOEX
   dwOSVersionInfoSize As Long
   dwMajorVersion As Long
   dwMinorVersion As Long
   dwBuildNumber As Long
   dwPlatformId As Long
   szCSDVersion As String * 128 ' up to here is OSVERSIONINFO vs EX
   wServicePackMajor As Integer ' 8 bytes larger than OSVERSIONINFO
   wServicePackMinor As Integer
   wSuiteMask As Integer
   wProductType As Byte
   wReserved As Byte
End Type

' APIs used to manage the 32bpp DIB
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" (ByRef Destination As Any, ByVal Length As Long, ByVal Fill As Byte)
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hDC As Long, ByRef pBitmapInfo As Any, ByVal un As Long, ByRef Pointer As Long, ByVal Handle As Long, ByVal dw As Long) As Long
Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdcDest As Long, ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, ByVal nWidthDest As Long, ByVal nHeightDest As Long, ByVal hdcSrc As Long, ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, ByVal lBlendFunction As Long) As Long
Private Declare Function SetStretchBltMode Lib "gdi32.dll" (ByVal hDC As Long, ByVal nStretchMode As Long) As Long
Private Declare Function GetObjectType Lib "gdi32.dll" (ByVal hgdiobj As Long) As Long
Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal uObjectType As Long) As Long
Private Declare Function GetIconInfo Lib "user32.dll" (ByVal hIcon As Long, ByRef piconinfo As ICONINFO) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function SetDIBitsToDevice Lib "gdi32.dll" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal dX As Long, ByVal dY As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, ByRef Bits As Any, ByRef BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, ByRef lpBits As Any, ByRef lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function OffsetRgn Lib "gdi32.dll" (ByVal hRgn As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Const STRETCH_HALFTONE As Long = &H4&
Private Const OBJ_BITMAP As Long = &H7&
Private Const OBJ_METAFILE As Long = &H9&
Private Const OBJ_ENHMETAFILE As Long = &HD&

' APIs used to create files
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetFileSize Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpFileSizeHigh As Long) As Long
Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As Any) As Long
Private Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, ByRef lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Const INVALID_HANDLE_VALUE = -1&

' ////////////////////////////////////////////////////////////////
' Unicode-capable Drag and Drop of file names with wide characters
' ////////////////////////////////////////////////////////////////
Private Declare Function DispCallFunc Lib "oleaut32" (ByVal pvInstance As Long, _
    ByVal offsetinVft As Long, ByVal CallConv As Long, ByVal retTYP As VbVarType, _
    ByVal paCNT As Long, ByRef paTypes As Integer, _
    ByRef paValues As Long, ByRef retVAR As Variant) As Long
Private Declare Function lstrlenW Lib "kernel32.dll" (lpString As Any) As Long
Private Declare Function GlobalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long

' ////////////////////////////////////////////////////////////////
' Unicode-capable Pasting of file names with wide characters
' ////////////////////////////////////////////////////////////////
Private Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As Long
Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
Private Declare Function CloseClipboard Lib "user32.dll" () As Long
Private Type FORMATETC
    cfFormat As Long
    pDVTARGETDEVICE As Long
    dwAspect As Long
    lIndex As Long
    TYMED As Long
End Type
Private Type DROPFILES
    pFiles As Long
    ptX As Long
    ptY As Long
    fNC As Long
    fWide As Long
End Type
Private Type STGMEDIUM
    TYMED As Long
    Data As Long
    pUnkForRelease As IUnknown
End Type
' ////////////////////////////////////////////////////////////////


' used to create the checkerboard pattern on demand
Private Declare Function FillRect Lib "user32.dll" (ByVal hDC As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Private Declare Function OffsetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

' used when saving an image or part of the image
Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
Private Type SafeArray
    cDims As Integer
    fFeatures As Integer
    cbElements As Long
    cLocks As Long
    pvData As Long
    rgSABound(0 To 3) As Long ' reusable UDT for 1 & 2 dim arrays
    ' array items: 0=1D item count, 1=1D LBound, 2=2D item count, 3=2D LBound
End Type

Private Type ICONINFO
    fIcon As Long
    xHotspot As Long
    yHotspot As Long
    hbmMask As Long
    hbmColor As Long
End Type
Private Type BITMAPINFOHEADER
    biSize As Long
    biWidth As Long
    biHeight As Long
    biPlanes As Integer
    biBitCount As Integer
    biCompression As Long
    biSizeImage As Long
    biXPelsPerMeter As Long
    biYPelsPerMeter As Long
    biClrUsed As Long
    biClrImportant As Long
End Type
Private Type BITMAPINFO
    bmiHeader As BITMAPINFOHEADER
    bmiPalette As Long
End Type

Private Enum eOScapability
    osAlphaBlendUsable = 1  ' then AlphaBlend enabled & used when needed
    osGDIplusUsable = 2     ' then GDI+ enabled & used when needed (set in isGDIplusEnabled)
   'oszLIBusable = 4        ' then zLib enabled & can be used to create/read PNGs (no longer used, tested as needed)
    osWin2KorBetter = 8     ' AlphaBlend capable system else it isn't for these classes. See isAlphaBlendFriendly property for more info
    osWin98MEonly = 16      ' Win98 or WinME. When m_OScap includes osWin98MEonly+osAlphaBlendUsable then user overrode isAlphaBlendFriendly
    osGDIplusNotAvail = 32  ' then NT4 w/less than SP6 or Win95. Otherwise system is GDI+ capable else it isn't
    osIsNT = 64             ' NT-based system. Unicode compatible
End Enum

Public Enum eImageFormat    ' source image format
    imgError = -1  ' no DIB has been initialized
    imgNone = 0    ' no image loaded
    imgBitmap = 1  ' standard bitmap or jpg
    imgIcon = 3    ' standard icon
    imgWMF = 2     ' windows meta file
    imgEMF = 4     ' enhanced WMF
    imgCursor = 5  ' standard cursor
    imgBmpARGB = 6  ' 32bpp bitmap where RGB is not pre-multiplied
    imgBmpPARGB = 7 ' 32bpp bitmap where RGB is pre-multiplied
    imgIconARGB = 8 ' XP-type icon; 32bpp ARGB
    imgGIF = 9      ' gif; if class.Alpha=True, then transparent GIF
    imgPNG = 10     ' PNG image
    imgPNGicon = 11 ' PNG in icon file (Vista)
    imgCursorARGB = 12 ' alpha blended cursors? do they exist yet?
    imgCheckerBoard = 64 ' image is displaying own checkerboard pattern; no true image
End Enum

Public Enum ePngProperties      ' following are recognized "Captions" within a PNG file
    pngProp_Title = 1           ' See cPNGwriter.SetPngProperty for more information
    pngProp_Author = 2
    pngProp_Description = 4
    pngProp_Copyright = 8
    pngProp_CreationTime = 16
    pngProp_Software = 32
    pngProp_Disclaimer = 64
    pngProp_Warning = 128
    pngProp_Source = 256
    pngProp_Comment = 512
    ' special properties
    pngProp_Miscellaneous = 1024 ' this is free-form text can be of any length & contain most any characters
    pngProp_DateTimeModified = 2048  ' date/time of the last image modification (not the time of initial image creation)
    pngProp_DefaultBkgColor = 4096   ' default background color to use if PNG viewer does not do transparency
    pngProp_FilterMethod = 8192        ' one of the eFilterMethods values
    pngProp_ClearProps = -1     ' resets all PNG properties
End Enum

Public Enum eTrimOptions    ' see TrimImage method
    trimAll = 0             ' can be combined using OR
    trimLeft = 1
    trimTop = 2
    trimRight = 4
    trimBottom = 8
End Enum

Public Enum eScaleOptions   ' See ScaleImage method
    ScaleToSize = 0         ' [Default] will always scale
    scaleDownAsNeeded = 1   ' will only scale down if image won't fit
    ScaleStretch = 2        ' wll always stretch/distort
End Enum

Public Enum eGrayScaleFormulas
    gsclNTSCPAL = 0     ' R=R*.299, G=G*.587, B=B*.114 - Default
    gsclCCIR709 = 1     ' R=R*.213, G=G*.715, B=B*.072
    gsclSimpleAvg = 2   ' R,G, and B = (R+G+B)/3
    gsclRedMask = 3     ' uses only the Red sample value: RGB = Red / 3
    gsclGreenMask = 4   ' uses only the Green sample value: RGB = Green / 3
    gsclBlueMask = 5    ' uses only the Blue sample value: RGB = Blue / 3
    gsclRedGreenMask = 6 ' uses Red & Green sample value: RGB = (Red+Green) / 2
    gsclBlueGreenMask = 7 ' uses Blue & Green sample value: RGB = (Blue+Green) / 2
    gsclNone = -1
End Enum

Public Enum eFilterMethods
    filterDefault = 0     ' paletted PNGs will use filterNone while others will use filterPaeth
    filterNone = 1        ' no byte preparation used; else preps bytes using one of the following
    filterAdjLeft = 2     ' see cPNGwriter.EncodeFilter_Sub
    filterAdjTop = 3      ' see cPNGwriter.EncodeFilter_Up
    filterAdjAvg = 4      ' see cPNGwriter.EncodeFilter_Avg
    filterPaeth = 5       ' see cPNGwriter.EncodeFilter_Paeth
    filterAdaptive = 6    ' this is a best guess of the above 4 (can be different for each DIB scanline)
End Enum

Public Enum eRegionStyles     ' See CreateRegion
    regionBounds = 0
    regionEnclosed = 1
    regionShaped = 2
End Enum

Public Enum eConstants      ' See SourceIconSizes
    HIGH_COLOR = &HFFFF00
    TRUE_COLOR = &HFF000000
    TRUE_COLOR_ALPHA = &HFFFFFFFF
End Enum

Private m_Tag As Variant            ' user-defined, user usage only. See TAG property
Private m_PNGprops As cPNGwriter    ' used for more advanced PNG creation options
Private m_StretchQuality As Boolean ' if true will use BiLinear or better interpolation
Private m_Handle As Long        ' handle to 32bpp DIB
Private m_Pointer As Long       ' pointer to DIB bits
Private m_Height As Long        ' height of DIB
Private m_Width As Long         ' width of DIB
Private m_hDC As Long           ' DC if self-managing one
Private m_prevObj As Long       ' object deselected from DC when needed
Private m_osCAP As eOScapability ' See eOScapability enumeration above
Private m_Format As eImageFormat ' type of source image
Private m_ManageDC As Boolean   ' does class manage its own DC
Private m_AlphaImage As Boolean ' does the DIB contain alpha/transparency
Private m_GDItoken As Long
Private m_ImageByteCache() As Byte  ' should you want the DIB class to cache original bytes
' ^^ N/A if image is loaded by handle, stdPicture, or resource

Private m_GDIplus As cGDIPlus   ' maintains instance to speed up drawing
Private m_KeepGDIplusActive As Boolean

' NEW SECTION *******************************************************************************
'                   CLASS INITIALIZATION & TERMINATION ROUTINES
' *******************************************************************************************


Private Sub Class_Initialize()

    ' Determine operating system for compatibility of 32bpp images
    ' http://vbnet.mvps.org/code/helpers/iswinversion.htm
    ' http://msdn2.microsoft.com/en-gb/library/ms724834.aspx
    
   Dim osType As OSVERSIONINFOEX
   Const VER_PLATFORM_WIN32_WINDOWS As Long = 1

   ' Retrieve version data for OS.
   osType.dwOSVersionInfoSize = Len(osType)
   If GetVersionEx(osType) = 0 Then
      ' The OSVERSIONINFOEX structure is only supported
      ' in NT4/SP6+ and NT5.x, so we're likely running
      ' on an earlier version of Windows. Revert structure
      ' size to OSVERSIONINFO and try again.
      osType.dwOSVersionInfoSize = Len(osType) - 8
      Call GetVersionEx(osType)
   End If
   
    If osType.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then

        If osType.dwMinorVersion = 0 Then ' Win95; can't use AlphaBlend nor GDI+
            m_osCAP = osGDIplusNotAvail

        Else ' flag as Alphablend disabled, but capable & is Win98/ME
            m_osCAP = osWin98MEonly
        End If

    Else

        If osType.dwMajorVersion > 4 Then ' if Win2K or better
            m_osCAP = osAlphaBlendUsable Or osWin2KorBetter ' flag as AlphaBlend enabled (Win2K or better) and capable

        Else ' WinNT4. If SP6 or better than GDI+ capable else not. Regardless, not AlphaBlend capable
            If osType.wServicePackMajor < 6 Then m_osCAP = osGDIplusNotAvail
        End If
        m_osCAP = m_osCAP Or osIsNT

    End If

    ' Note for programmers:  To test the spt_Win9xBlend function on systems with GDI+
    ' 1. Unrem next line
    '   m_osCAP = osGDIplusNotAvail
    ' 2. Rem out the next two lines
    Me.isGDIplusEnabled = True  ' attempt to start GDI+, test system capability, add osGDIplusUsable to m_OScap
    If Me.isGDIplusEnabled Then Me.HighQualityInterpolation = True
    
    m_Format = imgError

End Sub

Private Sub Class_Terminate()
    DestroyDIB ' simply clean up
End Sub

' NEW SECTION *******************************************************************************
'                           PUBLIC PROPERTIES AND METHODS
' *******************************************************************************************


Public Property Let Alpha(isAlpha As Boolean)
    m_AlphaImage = isAlpha  ' determines the flags used for AlphaBlend API
    ' this flag is set by the various image parsers; setting it yourself
    ' can produce less than desirable effects.
    ' Used in Me.Render & Me.TrimImage, cPNGwriter.OptimizeTrueColor & cPNGwriter.PalettizeImage
End Property
Public Property Get Alpha() As Boolean
    Alpha = m_AlphaImage
End Property

Public Property Let HighQualityInterpolation(Value As Boolean)
    ' When possible GDI+ will be used for stretching & rotation.
    ' If GDI+ is used,then high quality equates to BiCubic interpolation
    ' If not used, then BiLinear (manual processing) will be used.
    ' If High Quality is false, then Nearest Neighbor (very fast, less quality) interpolation used
    m_StretchQuality = Value
End Property
Public Property Get HighQualityInterpolation() As Boolean
    HighQualityInterpolation = m_StretchQuality
End Property

Public Property Get ImageType() As eImageFormat
    ImageType = m_Format    ' returns image format of the source image
End Property
Friend Property Let ImageType(iType As eImageFormat)
    m_Format = iType    ' set by the various image parsers. This is not used
    ' anywhere in these classes, you can do with it what you want -- for now.
End Property

Public Property Let ManageOwnDC(bManage As Boolean)
    ' Determines whether or not this class will manage its own DC
    ' If false, then a DC is created each time the image needs to be Rendered
    Dim tDC As Long
    If bManage = False Then     ' removing management of DC
        If Not m_hDC = 0& Then   ' DC does exist, destroy it
            ' first remove the dib, if one exists
            If Not m_Handle = 0& Then SelectObject m_hDC, m_prevObj
            m_prevObj = 0&
        End If
        DeleteDC m_hDC
        m_hDC = 0&
    Else                        ' allowing creation of dc
        If m_hDC = 0& Then        ' create DC only if we have a dib to put in it
            If Not m_Handle = 0& Then
                tDC = GetDC(0&)
                m_hDC = CreateCompatibleDC(tDC)
                ReleaseDC 0&, tDC
            End If
        End If
    End If
    m_ManageDC = bManage
End Property
Public Property Get ManageOwnDC() As Boolean
    ManageOwnDC = m_ManageDC
End Property

Public Property Get isAlphaBlendFriendly() As Boolean
    isAlphaBlendFriendly = ((m_osCAP And osAlphaBlendUsable) = osAlphaBlendUsable)
    ' WinNT4 & below and Win95 are not shipped with msimg32.dll (AlphaBlend API)
    ' Win98 has bugs & would believe that WinME is buggy too but don't know for sure
    ' Therefore, the Rendering in this class will not use AlphaBlend on these
    ' operating systems even if the DLL exists, but will use GDI+ if available
    ' Can be overridden by setting this property to True
End Property
Public Property Let isAlphaBlendFriendly(Enabled As Boolean)
    ' This has been provided to override safety of using AlphaBlend on Win9x systems.
    ' Caution. Only set this when rendering to a known device dependent bitmap (DDB)
    ' Alphablend can crash when rendering DIB to DIB vs DIB to DDB. Be warned.
    If Enabled = True Then
        ' Overriding in play: allow AlphaBlend if system is Win98 or better
        ' By default this is already set for Win2K or better
        If ((m_osCAP And osWin2KorBetter) = osWin2KorBetter) Then
            m_osCAP = m_osCAP Or osAlphaBlendUsable
        ElseIf ((m_osCAP And osWin98MEonly) = osWin98MEonly) Then
            m_osCAP = m_osCAP Or osAlphaBlendUsable
        End If
    Else
        m_osCAP = m_osCAP And Not osAlphaBlendUsable ' disallow AlphaBlend
    End If
End Property
Public Property Get isGDIplusEnabled() As Boolean
    ' identifies if GDI+ is usable on the system.
    ' Before this property is set, GDI+ is tested to ensure it is usable
    isGDIplusEnabled = ((m_osCAP And osGDIplusUsable) = osGDIplusUsable)
End Property
Public Property Let isGDIplusEnabled(Enabled As Boolean)
    ' Sets the property. If set to False by you, GDI+ will not be used
    ' for any rendering, but still may be used to create PNG files if needed
    
    ' You can reset it to true at any time. If the system won't support
    ' GDI+, then the True setting will simply be ignored -- no harm, no foul
    ' To test success:  c32class.isGDIplusEnabled=True: If c32class.isGDIplusEnabled=True Then ' success
    
    If Not Enabled = Me.isGDIplusEnabled Then
        m_osCAP = (m_osCAP And Not osGDIplusUsable)
        If Enabled Then
            If (m_osCAP And osGDIplusNotAvail) = 0 Then ' else Win95, NT4 SP5 or lower
                Dim cGDIp As cGDIPlus
                If m_GDIplus Is Nothing Then
                    Set cGDIp = New cGDIPlus
                Else
                    Set cGDIp = m_GDIplus
                End If
                If cGDIp.isGDIplusOk() = True Then m_osCAP = m_osCAP Or osGDIplusUsable
            End If
        End If
    End If
End Property

Public Property Let gdiToken(Token As Long)
    ' Everytime a GDI+ API function is called, the class calls GDI+ apis to
    ' create a GDI+ token first then destroys the token after the function is called.
    
    ' This occurs quite often. However, you can create your own token by calling
    ' GdiplusStartup and then passing the token to each class for the class to use.
    ' You would call GdiplusShutdown during your main form's Terminate event to
    ' release the Token.
    
    ' When Token is zero, the classes will revert to creating a token on demand.
    ' When the Token is not zero, any other DIB class created by this class will
    ' pass the token as needed. The only routine that can create a new instance and
    ' returns that new instance is the CreateDropShadow method. You must set the
    ' token for that class at some point for that dropshadow class to use it.
    
    m_GDItoken = Token
    
End Property
Public Property Get gdiToken() As Long
    ' returns the GDI+ token if one was created
    gdiToken = m_GDItoken
End Property

Public Property Let Tag(vValue As Variant)
    If IsObject(vValue) Then
        Set m_Tag = vValue
    Else
        m_Tag = vValue
    End If
End Property
Public Property Set Tag(vValue As Variant)
    Me.Tag = vValue ' use the object check in the Let property
End Property
Public Property Get Tag() As Variant
    If IsObject(m_Tag) Then
        Set Tag = m_Tag
    Else
        Tag = m_Tag
    End If
End Property


' NEW SECTION *******************************************************************************
'                               PUBLIC READ-ONLY PROPERTIES
' *******************************************************************************************

Public Property Get Width() As Long
    Width = m_Width     ' width of image in pixels
End Property
Public Property Get Height() As Long
    Height = m_Height   ' height of image in pixels
End Property
Public Property Get BitsPointer() As Long
    BitsPointer = m_Pointer ' pointer to the bits of the image
End Property
Public Property Get scanWidth() As Long
    scanWidth = m_Width * 4&    ' number of bytes per scan line
End Property
Public Property Get Handle() As Long
    Handle = m_Handle   ' the picture handle of the image
End Property
Public Property Get isZlibEnabled() As Boolean
    ' Read Only
    ' To create PNG files, GDI+ or zLib is required. This property informs
    ' you if zLIB exists in the system's DLL path
    isZlibEnabled = iparseValidateZLIB(vbNullString, 0, False, False, True)
    
End Property

' This setting will keep the current cGDI+ class active which
' prevents destroying the GDI+ hImage and Token objects.  This
' can speed up rendering. This option SHOULD NOT be set when the
' class is not compiled. Else crashes will happen when
' user hits END or VB toolbar's STOP button while in IDE
Public Property Get KeepGDIplusActive() As Boolean
    KeepGDIplusActive = m_KeepGDIplusActive
End Property
Public Property Let KeepGDIplusActive(keepActive As Boolean)
    m_KeepGDIplusActive = keepActive
    If keepActive = False Then
        Set m_GDIplus = Nothing
    ElseIf Me.isGDIplusEnabled = False Then
        ' can't set to True if GDI+ not installed
        m_KeepGDIplusActive = False
    End If
End Property


' NEW SECTION *******************************************************************************
'                                       PUBLIC METHODS
' *******************************************************************************************

Public Function LoadPicture_File(ByVal FileName As String, _
                                Optional ByVal iconCx As Long, _
                                Optional ByVal iconCy As Long, _
                                Optional ByVal SaveFormat As Boolean, _
                                Optional ByVal iconBitDepth As Long = 32) As Boolean

    ' PURPOSE: Convert passed image file into a 32bpp image
    
    ' Parameters.
    ' FileName :: full path of file. Validation occurs before we continue
    ' iconCx :: desired width of icon if file is an icon file. Default is 32x32
    ' iconCy :: desired height of icon if file is an icon file. Default is 32x32
    ' SaveFormat :: if true, then the image will be cached as a byte array only
    '   if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
    ' iconBitDepth :: the desired bit depth of an icon if the resource is an icon file
    
    ' Why would you want to save the bytes? If this is being used in a usercontrol,
    ' saving the bytes will almost always be less size than saving the 32bit DIB.
    ' Additionally, these classes have the ability to get different sizes from
    ' the original source (i.e., WMF, icon, cursors) if available, but if the
    ' 32bit DIB is saved, it is a constant size. The potential of different sizes
    ' could allow better resizing of the image vs stretching the DIB.

    On Error Resume Next
    Dim hFile As Long
    
    hFile = iparseGetFileHandle(FileName, True, ((m_osCAP And osIsNT) = osIsNT))
    If hFile = INVALID_HANDLE_VALUE Then Exit Function
    
    If GetFileSize(hFile, 0&) > 56 Then
        
        ' no image file/stream can be less than 57 bytes and still be an image
        Dim aDIB() As Byte  ' dummy array
        LoadPicture_File = spt_LoadPictureEx(hFile, FileName, aDIB(), iconCx, iconCy, 0&, 0&, SaveFormat, iconBitDepth)
    
    End If
    CloseHandle hFile
    
End Function

Public Function LoadPicture_Stream(inStream() As Byte, _
                                    Optional ByVal iconCx As Long, _
                                    Optional ByVal iconCy As Long, _
                                    Optional ByVal streamStart As Long = 0&, _
                                    Optional ByVal streamLength As Long = 0&, _
                                    Optional ByVal SaveFormat As Boolean, _
                                    Optional ByVal iconBitDepth As Long = 32) As Boolean
    
    ' PURPOSE: Convert passed array into a 32bpp image
    
    ' Parameters.
    ' inStream:: byte stream containing the image. Validation occurs below
    ' iconCx :: desired width of icon if file is an icon file. Default is 32x32
    ' iconCy :: desired height of icon if file is an icon file. Default is 32x32
    ' streamStart :: array position of 1st byte of the image file. Validated.
    ' streamLength :: total length of the image file. Validated.
    ' SaveFormat :: if true, then the image will be cached as a byte array only
    '   if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
    ' iconBitDepth :: the desired bit depth of an icon if the resource is an icon stream
    
    ' Why would you want to save the bytes? If this is being used in a usercontrol,
    ' saving the bytes will almost always be less size than saving the 32bit DIB.
    ' Additionally, these classes have the ability to get different sizes from
    ' the original source (i.e., WMF, icon, cursors) if available, but if the
    ' 32bit DIB is saved, it is a constant size. The potential of different sizes
    ' could allow better resizing of the image vs stretching the DIB.
    
    Dim nrDims As Long
    If iparseArrayProps(VarPtrArray(inStream), nrDims) = 0& Then Exit Function
    If nrDims > 1 Then Exit Function
    
    If streamStart < LBound(inStream) Then streamStart = LBound(inStream)
    If streamLength = 0& Then streamLength = UBound(inStream) - streamStart + 1&
    If streamLength < 57 Then Exit Function
    ' no image file/stream can be less than 57 bytes and still be an image
    LoadPicture_Stream = spt_LoadPictureEx(0&, vbNullString, inStream, iconCx, iconCy, streamStart, streamLength, SaveFormat, iconBitDepth)

End Function

Public Function LoadPicture_Resource(ByVal ResIndex As Variant, ByVal ResSection As Variant, _
                            Optional VBglobal As IUnknown, _
                            Optional ByVal iconCx As Long, _
                            Optional ByVal iconCy As Long, _
                            Optional ByVal streamStart As Long = 0&, _
                            Optional ByVal streamLength As Long = 0&, _
                            Optional ByVal iconBitDepth As Long = 32) As Boolean

    ' PURPOSE: Convert passed resource into a 32bpp image
    
    ' Parameters.
    ' ResIndex :: the resource file index (i.e., 101)
    ' ResSection :: one of the VB LoadResConstants or String value of
    '       your resource section, i.e., vbResBitmap, vbResIcon, "Custom", etc
    ' VbGlobal :: pass as VB.GLOBAL of the project containing the resource file
    '       - Allows class to be mobile; can exist in DLL or OCX
    '       - if not provided, class will use resource from existing workspace
    '       - For example, if this class was in a compiled OCX, then the only way
    '           to use the host's resource file is passing the host's VB.Global reference
    ' iconCx :: desired width of icon if file is an icon file. Default is 32x32
    ' iconCy :: desired height of icon if file is an icon file. Default is 32x32
    ' streamStart :: array position of 1st byte of the image file. Validated.
    ' streamLength :: total length of the image file. Validated.
    '   -- See LoadPicture_Stream for the validation
    ' iconBitDepth :: the desired bit depth of an icon if the resource is an icon
    
    ' Tips:
    ' 1) Store 32bpp bitmaps in the "Custom" resource always. Storing in the
    '       Bitmap resource can change color depth of the image created by VB
    '       depending on your screen settings
    ' 2) Icons, normal bitmaps, & cursors are generally stored in their own sections
    '       However, with icons containing multiple formats, VB will extract the
    '       closest format to 32x32. May want to consider sThen ' sundle hFile
  '       - e ' sundluO)
                         BiLinePropelosest f,Dunctsystembility (nx32. lzing of the imrror

E' iconCy :: desirle; can exist in DLL or OCX
    '     b           As mat to 32x32. May w  depend32x32. May w  IME is b  IME is b  ileconCy As Loed he3cg of file names icon
    imgWMystembility                      'CnePropelosest fnot proviendly(1=IB c.
    ' inStream:: byif the resource is          ames icon
    imcanL or OCmage
    LoadPicture_Strea- the rDims A2ur WinME. When m_OSc0
    ' te


















ByVal Savalidat)t :: arr   ' fI  ' te

oolean
e file. Validated.
  ng thrksp Then     '***of the imrror

E' iconCy :: desirleen BitBlt Libb pro or VB too    am(C%           u      ility (' sundluO)
       ' Yu VB too    am(C   ' special he ie        ames icon
    imcanL Ys icon
    imcanL Ys icon
    imiteF' Yonly
 B_is b  IME is9        iBAs Loed'     b         H SaveForByReffys str_a , _
l OCX
 i+++++++    ' height oed when s )e GDI+ hImaunction
Reffys ksp The
' Cl Afys str_'             is9     e) = osU your own           is9) As Lone As Long
    
    hFiength :: total lengths DIB :U is9) 






 Noe file
   E FileNown           is9c
   21 stretch/distorta'           tocaaaaaaaaa



 Noe
 Noe)Coken         ic    ' used=ure_Streamaaaaa(ByRef lpRect Asitmap Aon
   l Afys.            Di tCis9) 
 0&, 0eamaaaaa(ByRcse,  file is tBlt Lib  this treamLength, SaIBJ_ENHMETA
   s  
 /distorta'ass tDIB    erty
Public Property Get BitsPouaa(B'ass tDIB    ebr_PaetEWhen m_OSc0
   ' icoNL osType.dwMial ByVal DC As Long
    GDI+ hImNL osType.y) TheGart, streamLen    de your screeeeeeeeeeeee-
   deeeeeeeee-
   d                         Optionf theefile is tBlt' Tl almo True_Stream = spt_LoadPictureEx(0&, vbNur'ct' Tl almo i.YPublic PrD+lity (  ' inSnot provmNL pha ble pha blong, ByRef pBitmENHe. Validated.
  ng thrksp Then     '***of the imrror

ha ble phageT?regionlean
e file. Validated.
  ng thrksp Then     '***of the imrror

E' iconCy :: desirleen BitBlt Libb pro or VB too    am(C%           u    esirleen Bi.fn on demeamLength => eScaleOptions   ' See ScaleImage method
    ScaleToSize = 0     ge
   Vm: one of thms thms thms thms thms thms thms thms thms thms thms thms thms thmsone : onLenso///E or OCX ' streamStart :: array position of 1st byte of the image file. Validated.
 imrror
s Long, isn't
  sThen 'BitDeptAs Limag
s Lonmtion of 1st byte of the image file. Validated.
 imrror
s Long, isn't
  sThed in_IconSi
    ' 32bvalidunctsysteer.EncodeFiB////
amLength => nNumbtByVaonly 
        If m_I  
End Property
Public Property ly 
 aleOptions   ' See ScaleImage method
    ScaleToSize = 0     ge
   Vm: one of thms thms thms thm
    isZl/Ety (  ' inSnot provst by the only way
    '           to use the host's resource file is passing the host's VB.Global reference
    ' ic is passing the host's VB.Global reference
    ' ic is p(sourcis kernel32" (ong
    Ha
    ' ic is p(sourcis kersThewdle is passirsThewdleseValidahewdle isssirsThcurs quitc way        u    esirleen Bi.fn on demeamLength => eScenray positigth =>uld yodleseValssGDIplu foul
 2alss' hequitc way5i byte of th ng use*******sitigth***iTPeryFiing oSuby the lAdesirleen BitBlt Libbray posite icon if file isdesirleenype.y) TheGarthe image wil=ype.y) Thedc image vs d



led OCtream = spt_LoadPict  '   -- Se extrae isdinatepe BITMAPy the lAdesirlheGarthe imageTMAPy thed'    Validated.
 imrron   erty
PudFilmDLE_VALUE imageRity (' sunNumbtByVaonl Afys.    MAPy the lmrron   ertIf m_I  
End PrOhms thmsI  'WIN32_  Ifevery 98 or OFriendly property for more info
    osWin98MEonly  suost'1yl Afys.   msI  'WIN32_  IfeveFormsource fi Afys.    suost'1yl Afys.   mseeition issirsThcurgsepGDIplufi Afys.    sm(Ospt_LoailterAd, vbNullStringxM**


fys.   mse v


ByVlu foul
,ptsystem(hms thS=   Vm: one of thms thce mst_LoadPcyVlu ffffffffffV  mse v


ByVlu fo msee  mseeition issirsTh ' thenhost'/:      Scat'/:      Sc'osIScat'/:  N5ewdle is
  s Sc'osIScat'/:  N5ewdle is
  s Sc'osIScat'/:  N5ewdle is
  s Sc'osIScat'/:  N5ewdle is
  s Sc'osl("kernel32.dll" (ByVal hMem As Long) As Long

' /////////
    regioirsThcSc'o              Optioifica As Long)le. Validated.
m As Lotom" resource mOnly set _I nd If
    Ce
s is not ************Ipie mOnHODS
' lie validationy time. If not ********p GDI+ pha ct the
    'dis
  s Sc'osl("Ipie mOnHODS*****y it
            ' fbhe lmrron   ertIw pha c l AfysS*****y  imon '1yl Af(
 umbtByVaonly ce you w lmrron   ertIw& if z le
     fbhe lmonly    t depttByVaonly ce   Optiss b ur oertlmrrone
   Ioon   ertIw& if z le
     used='source mOnly se    **iTPer


ByVlu(rcis kersThe'    Validated.
mAbpg********2. May w  de it is usable
    isGDIplusEnabled = ((m_osCAP AY  isGDIpsno image file/stream cgth =

BP AY  isGDIa4rtIw&s thmsI  'Wr mOnly set _I nd If

BP m   Vof asI  'Wr conCy :: desirleen BitBlt Libb prodmin the e mOnly rmin t         . May w  de   suost'1ylseArrayPropscic iscic one of thms Inames wme, True, ((m_osCAP And osIs of tct' Tl almo i.YPubline of t   . M2lmoee See  widereamLength As (m_o/stream can be less  the e mOnlyei'), ((m7Pouaa(B'asnnnnnnnnnn=ype.y) ror = -1  ' th As (m rmin t         . May w  de   suosP AY  isGDIps=ype.y)e.y) ror = -1  ' th As (m rmin t         . May w  d-1  ' ttL.y) r/////Ss=y t         . bames wme, True,p = -1ring value valhmsf  ' 5
Public ProprCERTIESO isGDIplusEnabled = (s.   rray
   Enunly waage file  End OT be 
led OCtream = spt_Lo, stre ur oertlmrronees if GD e, Fil True, ((ronees if GD e,rceUIplusEnabled = (s.   rray
   Enunly waage file  End OT be 
led OCtream = sp]image w2s
  s Sc
    If GetFilLype.y)e.Sdot compilst always beIw cG, ((to use tty method
    trimAll = 0   u=R*.299, G=G*.587, B=B*.1 2lmoee Seed.
    ' We u(e) =             Optional' dummy array
eA  . own   A:  ''t supportlean
e file. Validated.
  ng thrksp Tsource file index (i.e., 101)
   sActive = m_ys ' We u(e) =   L phaive = m_ys ' We u   :alidu     ' We32bie e mOnl     '        L aTsysfys ' We u   :ali<.587l
,ptnli<.587ys ' WeK '  rce file u(e) =   L phaive = m_ys ' Wenabcb imon '1yl Af(
 umbtByVaonly ce you w lmrron   ertIw& if v(g[aonly ccgthmrro8MEon
,ptnlime of initial image creation)
 nt sizes fro= 5  ' standard cursor
    imgBmpAimage filetsirleen Biaonly ccgthmrro8MEonrseen ^so, c lue    t line
  un)
 nt sizew
   sActive  sizew
   sActive  sizew
   se  sizevBlor depth ofimage creation)
 nt i', is 
  tl True, :sCAP = R1ype icoClihe
' Cl Afys str_'    eyidated.
MatiovBlor d&'    **********  Ifce fiatiovBlor de
' Cs       Optioifi fiatiMirsThcSc'o      s tFilLype.y)e.Sdot compilst always beIw revObj
n tue, :sCAP = R11111111We u   ngth ::f icon if file ngth X ' stgsGDIplusEper     ' udesirlheon't know fof

Bs of tct' Tadde
' Cs       Optioifi fi fi = 0 Then ' else Win95, NTByVlheoi' Cs       Optioifi fiatiMirsThcSc'o      s tFilLype.y)e.Si revObj5
  un   osh X ' stgsGDIp&e creation)
 nt e, :sCAP = R1ype ipscic R1ype ipscic Rtl    **pe.y)e.Si rep&PoneesitsPointer() As Longen ' e&    . bames wme    m_Formac'osIScat'/:ue, True,,&6mi revd) = 0  revObj5
  un udes sure

    i5
  u. suremong, By*pe.y)e.Si rep&Poi
    'DR1ype ipscic vBlon)
    filt
    Dim hmong, By*pe.y)e.Si ion GetyR11111111We u   ngtheY0 The system.
ppe.y)e'/:ue,,neatcyVlu ffffffffffV  ms/1111115i byte of th ng use*******sitigth***iTPeryFiing oSuby the lAdesirleen BitBlt fffffe thrk+r     ' usundle hFile
  '       - e ' sundis passing the host's  imcanL Ys = (s.   epfffffe seFilter_U pong = 0&, _
             Sc'o  s  imLRlLype.y calls GDI+ apissssssssssssssssssssssJm_hDC RlL
BP  WinSc'o  s As eImageF Only
XcaleImage method
    Scae Win95, 95, 95ropellt
    Din   ertIf m_ in DLLLLLLLLLLLLs wme, True, (dUsa)nt sizes fro= 5  ' standa roperty


' BmpAim'(dUsaRyI rep&Poi
    'DR1ype LLLs wmeh of the image file. Validated.
    ' SaveFormat :: if true, then the image will be cached as a byte array only
    '   if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
    ' iconBitDepth :: the desired bit depth of an icon if(.
    'nalFormat to retrieve them.
    ' icoiTPew     Bitmis
  nc Proper'nalFormat to retrievely set _I nd IfyR11111S   'nacached as aewdle is
  s uR  ' If not u. retrievely set _I nde lAdesfe the0   s:1S   'nac Scpethod
   uM  End If
        Delet7ithe image was su. roneesitsPointer() As Longen ' e&    . bameed)
    oil True, ((ronehU **pe.y)e.Siiat to rnrsp.Siimeed) As Longen ' e&    . b';O thie
    oil True, hcXen stre. b'**inrsp.SiimeedeEnd OT beongeehU *If

BP m   Vof asI  'Wr conCy :: desirc:bled = ((mFeng
         riev,. b'**inrsp.Sii
 u th various imat depth f n              Optional VBglobal As IUnknown, _
                            Optional ByVal iconCx As Long, _
                            Optional ByVal iconCy As Long, _
                            Optional ByVal streamStart As Long = 0&, _
              As Long = 0&, _
ve  sizew
   seUd    GDI+ not idUsa)nt eated andard curers.
sirl'    n savr osGDameed)
r     ' usun rmage creation)
 nt sizes fro= 5  'r)
r     sav=) = 0  revObj5
  un udes =) =he
' C)    n savr osGDameed)
r     ' usuurce imc5  'r:: desirc:bled = ((mFeng
)
r desirc:bled = e objectfron. b' ((ronehU **pe.y)e.Sate m_Handle As Long StretchQuatfron.B(m_Handhie
    oil True, hn t_Hasav=) = IN4)_Handle As Long Stretiiat to rnrsp.Siimeed) hod
   s Long =  ' standa roRay
eA  . own   A: ional By_
    rnrsp.Si =             OpOptioPB  sizewperty
Ipie mOnHODS****NC((mFeng
)
r desirus)
ve  sizew
   seUdto rnrsp.Siimry fast, leesirus)
ve  sizew be d='source mOnly se    **iTPerp  Di&  Optional hSc'osIlpe Lonehu. rone*iTPerp  a P         Perp  ao rnrsp.Si.y) TheGart, C s tFip.Sii
 u th varioutFip.S8p.Sii
 u th varioutF)
 nSBreation)
 nt i', is 5reation)
 nt i', is xt      Opt.+ tFip.Sii
 u st aip.Sii
 u th varioutFip.S8pRUE_COLOR = &HFF    Opt.+ tF si1mmmmmCmarsp.Siimry fast,s 5re   nc C s tFip.Si
 v          As mat  COLOR = &Hy fast,s U Thedc etermihp.Si
 e .FbnHODS
' lie validation e .FbnHODS
4 beD    . uyC s(
 e .FyVal iconBiboCOLOR = &Hy fast,s U ThPe .FbnHODnt i', ispt.+ tFip.Sii
 u st ai usu ***p.Siial iconCy As Lof the imagieated andard curers.
sirl'    n nly se ii,o, leesirus)
ve  sizew be =  ' standa rEYuse filtene
    F Onl
sirl'    n nly *******sipscic R1ype(verle
  - whether or no' standa rEND METHODS
' ********************sipsci'    n nly *******sipscic R1ype(verle
  - whether or no' standa rEND METHODS
' **********************pverle
  - whetub Clao DDB. Be warncriptida ngen ' e&    . b';O tnrsp.Siimeed) Asepend32x32.  ' e&   y As L - whthen high qtub Cla' e&   n the - whthen Long                                                                           ***ms/1111115i The potential ofength, SaveFormat, iconBitDepth)

End Function

Public Fblic Property ilst al/streamnter() APublics Long3vp, iconBitDepth)
potODS
' *****em,
End Enum
ce leToSize lasses, you can do with it what you want -- for now.
End Property
 (s.  f an icon i do with it tODS
' *****em,
End Enum
c an's  c'osIlpeAP And o c'osIlp  . Ml
 nSBr c    ' sFunction

Public Fbli    Opt.+ it what you want -- Fpt.+ it.lic Fblie ' usun rmablicitanhon

PheGart, C s tFip.Sii
 u th varioutFip.Sii
 u tht desirc:sart,
Phelh, SaveFRty Let Highepend32x32.   Optu(e) = ?   Optu(e) = ? 1ype(verle
  - whether or no' standa rEND METHODS
' ******Fpt.+     
ByVlu fouls         better -anda rENpeAd as a or no' standa rENmlic Fbli th variout - 
,rtah X ' stZ/fouls  a rEYuse filtene
    F dl. Only set thi[ for now.
EODS
he oinction
ustZ/fouls  a rEYuse fi32
    ' ssm_Tag termihpncreationStart < LBound(in(ptZ/fouls  a rEYuse=he
' BnHODS
 - 
,rtaocGDIncti**********m
ce leToSize lasses, youcset thi[/foulsyouc.B(Y     PUgth =>uld yodleseVa

' /pp(sourcis kersThewdle is passirsThewdleseValidahewdle isssirsThcurs quitc way        u  Priurcis kersThewdlwn   A: ional Ban
ig or no' standa r
             Sc'o  s  imLRlLyped youcsetBan
ig or no' ss
    '       oiatiMirshms thmsI  'WIN32_  IfevGd youcsetBan
e' ss
    '      **************uclls GDI+ api or no' sS1 youh As/////////////// icon///bIpGDIplusT Iariout -ge will      - As///////////(no' sS1resourcduce lresourcduce lresourcduce lresourcdbs) if aourcdb*m
ce leToSize lasses, youcset thi[/foulsyouc.B(YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYaroA
   ssAcyB. 1    u(  spt_Lormulas
    gsclNTSCPAL = 0     ' R=R*.299, G=G*.587, B=B*.114 - Default
    gsclCCIR709 = 1     ' R=R*.213, G=G*.715, B=B*.072
    gsclSimpleAvg = 2   ' R,G, and B = (R+G+B)/3
    gsclRedMask = 3     ' uses only the Red sample value: RGB = Red / 3
    g?   Optiona pable

 true, th, C 2ses only the RelosestS    u(  true, operty
 (s.  f an icon i d3es only the Relo8n i d3esquite sptiona E,then high quality equates to BiCubicOI cPNGwriter.EncodeFilter_Up
    filterAdjAvg = 4      ' se  ' iconart, C e fi Afy  **iTPer

 lmrron   ertIf m_I  use fi3 ,     betterus'i************* ND METHODSoSR iconart, C e fi Afy  **iTPer

 lmrron   ertIf m_I  use  Let Highepend32x32.   Optu(e) = ?   Optu(e) = ? 1ype(verle
  - whether or no' standa rEND METHnFr no''''''''''''''''
' *****(s.  GLOBIR709 = 1 Z          'o MEnd Enum
c an'sg'''
' ****3lE,then high quality ono' sS1reso
Publicccccccoinction
       
    '      oinct"no' sS1reso
Publicc
Pu) =e/   Di t,then hif) =e/  &.114 - Defy                 Di tCbfoSize = ************* Ne/   Di t,thed . bameted  ertize = ***********sirVB.GLOBAL ofe P         Perp  ao rnrsp.Si.y) TheGart, C s tFip.Sii
 u tR Optional ByVal h qualitptional ByVal h ii
 u tR OptP mPPrivate m_Handle As Long        ' handle to 32bpp DIB
Pri.Sii
 u 
    m_HandluR[/foulsyouc.Bw)) =e/  &Pe*****           u 
    m_obtptioter() Aurcduce lresourcdu          er

 lm' If norron   ertIw& si           u 
o MEnd EnTor no' sle As Lemle is passing the host's mr 2ses otream,ivate m'to BiCuing ton n high qu-S1resourcduc1YYY+bb0ate m'to BiCuing ton n high qu-n '1y' R,G' Saion)
 dl. Only set thi[ for now                                                                       m'to BiCuing ton n high qu-S1resourcduc1YYY+bb0ate m'to BiCuing ton n high qu-n '1y' R,G' Saion)
 dl. Only   Let Highepend32x32.   rB/:ue,ty Get 
sirl'verlemf n se  ' icerle
  - wlgse fi32
    ' ssm_Tag termihpncreationStart < LBound(in(ptZ/fouls  a rEYuN5en high qu-n '1y 
,rti tCbfoSize = ***** - wlgse eigh seTultiple formats, VB will extract the
    '                    m'topassing the host's mr 2te m'to to BiCuiA,ion)
 ly   Let:mr 2Propert***********c Fbli    Opt.+ i1*********er   yVal h quali*****SVlu ft***********cdach time the image Fbli  Fb****cdach time the image 0tnrsp.Siimeed) Asepend32x32.  ' e&   ybpt.+ i1***is s thms thmsHan                                  eed) Aseppend32x3Tag i*****ee 0tnrsp.SinSinSiThigh qu-S1resourcduc1YYY, _
   Asepend32x32.  ' e& 1iR = &Hy fast,s U ThPi'),ts,ion)/erle
  - whaaetOrginimagwsm_Tag s  0tnrsp.Siimt th.LonehetOrginimagw5will beetOrginim
    GD,s ginimagwsm&Y Longty eq
  - whether or ,ns      CLASS INITIALIZATION & TERMB1U, _
                      m'to BiCuing ton n high qu-S1resourcduc1YYY+
    ' 32bitfor                    Optionn file. Default is 32xs  a rEYuse Ru   G  ' couldoo BiCuing ton n higardtC ginimagwsm&Y  iconBitDepth :: thlt iime. If  '1yl Af(
dtC ginimaigh quality(iR = &Hy fast,s nly the f an iceYll not ued sample value: RGB = R ono' sS1rc,age y thic Fblie ' u OptP mPPriva isb           m'topassing
  n ceYlXA*******2. May w s nly the fInala ono' sS1rc,age y th******2. May wtU4l' ice = *,s ginimagwala ono' sS1rc,a osIs of tct' Tl almo i.YPubline of t   . M2lmoee m,5ewdle is
  s Sc'oHe. Validat        *out - 
,r)5ewXiS these
    ' oper usun rmage The2uSabilityyVaonly ce   OptY+
  u  ' allowinnal ByVal h ii
 u tR OptP mPPrivate m_Handle As Long        ' hal h ii
 u tR OptP mPPrivate ss LP mPPri?As Long AYLP DPPrivateLibinly ccgthmrrs           
  ly the fInala oP mPPrivate ss LP m3 = m_sGDIpluuing toSizeLong        'rrrrrre   OptY=oinct"no' ala oP mPPrivate ss LP m3 = ass.is '1y si  Fb****cdaaIME is b  ileconCy toSizeLm3 = astoSizeLong   sA2ur WinFblic Propefyy ccg f n          esourcdddddddIy) ror =age y th'D      ue y th'Db     B(YYYYYYe
   sAc    **peX3YYYYe
   sAc    ***nala ono'l LoadPictBC            pPictBC            pPictBC  no'l                  S,)b         
    F dl.y th'Db     B(YYYYYYe
   sAc    **peX3b ror = -1  iB(YYYYYYe
ate m_Handle ACYYYe
 compilst alwaysIcompilst alr usun rmage o'l LoadPictBC            pPwmnter()  useaa= Afy ltiona pable

 t1U, _
if true, th  iB(l' Yoning
  n e sys/
 - 
,rtaso
Pubf the DLL exists, but will u vor = -1mtBC            pPwmnter()  useaa= AfyEp useaa= Afy ltiona pable
_**nala ioy si  Fb*g AfyEp ub't
 ''t soy si  
  2_  Iists, but willecddddy ltiona pable
_**nala ioy si  Fb*g AfyEp ub't
 ''t soy si  
  2_  Iists, but willecddddy ltiona pable
_**nala ioy si  Fb*g AfyEp ub't
 ''t soy si  
  2_  Iists, but willecddddy ltiona pable
_**nala ioy si  Fb*g AfyEp ub't
 ''t ain(ptZ/fo but wil  spt_dimImage, cPNGwritee  ' icerle
  - wlgse fi32
    ' ssm_Tag termihpncrtl beetOrginim
kas in a compileimImage, cPNGwriteyEp  m_Handle AssS1resourcdle Ainim
kas   Di tCis9I AfyEp ub't
 ''t soy si  
  2ptZ/foulsml beetOrginim
kas in a compileimImageY+
  u  ' allowinnal ByVal h ii
 u,sts, but wi = Z/foulsmlinctiollusEnabled() AE sewritee c0sp(arginim

    gsc******** uinimagwmy ltiona pableYnctiollusErtl beetOrginim
kafoulsYYYYYYYYYYt seFiltd Token scic vBln    Validated.
+FenlPesthFb*g AfyEp ub't
 isn't, but wi = Z/foulsmlinctiosi  Fb*g AfyEl0t2bitfoprCERTIESO isGDIplusEnabled = (s.

 true, th, C 2ses only t, th, C 2ses onong, _
                             eed) Aseg() APublla ioy  filtene
    F Onl
sirl'    n nly *******sipscic R1ype(tP mPPriva isb           m'topass ma/****s  '    m'tritee  ' icer*****sipscic R1y'trit(   D M:,sts, bule Aicc
Pu) =e/   Di imageTMAPy thed'    Validated.
 imrron   erty
PudFilmDLE_VALUE imageRity(s.

 true, th, C 2s OptP m     ginim
kas in a compi
    gdIw&h =

BP AY  iist's VB.Global referef thms tc Xv' sS1r,rt&pin ddddy lso///E you want  Validab*g       x3Ta iist'ageh
PudFilmDLE_ iist'bm  '           to use tlSof  waage file  EndPriva ia i if thellowinnamethod
  twdle is
  s Sc'osl("kernel32.dll" (ByVal hMem As Long)  er or1    ' ssm_gmwwwwwwwas in a compileireferef thdy ltiona pable
_ng, inS+hely lbt th(   D M  2_ :: on m_H  eRthdy                :: on m_HhaBleFunal hMem As LongS+h          . re                    mI
_**na desired wi: on m_H  eOptional By s nly the fIna e mOs nly the fIna m_HhaBleFuna:GgeTMA1 EnOpto       D AC 2ses only t, th, C 2  mPes only t, erle
  - whGgem_HnOpto      msHan   si  
 pBtretc   sA2urag
s Lonmtion of 1st byte of the imageK '  rce file u(e) =   L phaive = m_ys ' Wenabcb imon '1yl Af(
 umbtByVaonly ce you w lmrrc0sp(argini-   am(C e fileed.
    If Enabled = !ep ccgthmrro8M2yl Af(
t's VB.Global re
  ie ' u114 retup DIB
P.R = &Hy ctive ,age y th******2. May w =   L pen hi(con '1yl Af(Ihe imag2 t, iconu          y th**n hi(c   
    '    cvt conu vor = -1mtBC          
   sosCAP AY  isGDIpsno 4iunal hMem As LongS+h e y1yl Af(Ihe imag2 t, i) True)
    
EndRir)5 = -ihrksp Tssssss
  u  ' allowLLLe.Af(Ihe imag2tIw& if z le
     used='source mOnly_**nala ioy si  Fb*g AfyEp ub't
 ''t ain(ptZ/fo but wil  spt_dimImage, cPNGwritee  ' iceri n savgS+h e y1ylXt ai miunal hMem oeri n savgSe  ' 3but wi = Z/ Z/foLnnly_**nala ioy si  _
                  
 magag2tIw& if z leavgSe  ' 3but w mOnHODS****NC((mFeng
)
ro but  magag2tIw& if z le '1y si  sed='s5ewdle is
 :: onh)

E(mbtByVa iconBi       
  8M2yl Af(
tla ioy fileedal hMem filltiona pable
_e   
   M2yl Af(
tla i     
  (
tla i     
  (
tltla ioy fileedal hMem filltiona pable
_e   
  busu ***p.eFBP  WinSc'o  s_            21 stre (
tla i  yEp ub't
tup DIcoiTPew l
sirl'    n   cvs(   D M:,sts, bule Aicc
Pu) =e/   Di imageTMAPy thed'    Validatend if system is Win98 or better
        ='t
tup DIcoiTPew ltend if syste Wenab           21the ThMem oea m_HhaBleFu th**do.Glo Af(
tla yEp uthe imagieate.Glo Af(
tla yEp in a comptd if systen

Pub(
tla yEp utc

Pub(
tla  cvt hod
5.eFBP  WinSpmageTMAPy teandle As       >, cPNGb    b)
 lth**n hi(c   
    '    cvt conu vor = -1mtBC          
e       9I XyVal hMem'Ie,rceUIs -1mtBC    ng, _
  e ,   '    cvt eate a . roneeMAPy thed'    Vad. e,r
)
rofor           tl Tmon 1art As e imag2tD+lity im
kas . roneeMAPy thed'   ps eart As  ue iist'syEp ub't
 ''t soy sAf( tc Xv'mtBC    ng, _
 rieeMNptionalnly ccgthmrro8MEonrseen ^so, c lue    t line
  un)
 nt sizew
   sActive Wro8MEonrsssssssssssssssssss  b)
 lth**sssssssssss. M2lmoee m,E(pable
loy sAf( tc X_Pn)
 treaBt thi[/fog2bitfor     qro8MEon
,ptnlim u  ' allowinnal                     reamStar fil ''t ng usecoClihe
 lth**n hs ei,e
rofor   *n     cyG m,E(pabesourcduc1YYY+bb0aowinnauretrieve them . ron ai lity n     cyowinnauretrieauretri
    . ronL(
tltla ioy fileedal hMeiourcdetri
    . ronL(
tltla'pone of the VB LoadResCourcvetri
    . ronL(
tltla'pone ronL(
tltla'p
 true, th,. ronL(
tltla ioy fileedal hMeiourcdetri
    . ronL(
tltla'p9tIw& if z leavgSe up a iBIhat you want -- Fpt(
ton   ertIw pha***is s As Long = 0)_**nala ioy so, cor     q. ron(=ageF     y n     cyos s Ass s  Fpt(
ton  d
5.eFBP  WinSpmageC(ks,c ltionS   Iw& if z le












T syste( AssOy iceYll not ued ed heigh   cyos P)_**nthed'   pnS   Iw& if z lssssssssss  b)
 lth**yste( . Validat        *                     OptiNpti *  , thIpsno 4iunt coEG*siribinly cc As cG   **nala ono'l LoadPictBC enS   +wltiona pa  m_Tag ,ssssssss  bnd If
End e  Optitream foS   a com or no'  seFiltd Tok .  Optitre If
End e  qro8MEon
,ty
Public Proper: roper'na s Sc'oost always be YoS   roper: ropessssss  o8MEof ^so, uA,ssssssss  onu vor = -1mtBC      aSc'oost ,able
loy sAf(         ource mOnl a rEYuNh
                Di im
kas . ronem(etopassise fiao with it tODS
  Perp  ao I Iw& if CE8MEon
,ty
, t, ic i+++' canon  d
5.eFBP 0  sn't
  sThed Ee u(embtByVaisdesirleenypeO,   esPubln hi(c   
  uBIhat you w
PudFilmUs tmrro8M   
 *s  'yowinnauretain(ptZ/fo  'yowinnauretembioper: r.      omk hi(c Dallt
eYll not ued GGGGp ' f        uBfusecoCl  o ron abn issssss  onse ThCl  o ron abn issssss) ifval re'8MEonrseen ^so, c lue    t line
  un)
 nt sizew
   sActive Wro8MEonrssssssssssss the to the reb  this treamsinctiollovBlor dhActive
   sAsS1 youh As///////////Nona pable
_e   
   M2yl Am im
 pable
_e   
   M2yl  ao I Iw& if CE8MEo,able
_e   
pl    
  (
tla i     
  (
tltla ioy fileedal hMem filltiona pable
_e   
  busu **
 umb       leedal hMem filltioy si  sed='s5ssss) ifval re'8MEonr ' Parame, t, ic i+++ w  0  sRudFilmUs tmrs sure

    i5
    sed=m  i5
 he stem(hms thS=   Vm: one      ueval re'8Mbb0aowinA)
rXx)Byle ib't ib'tCAP AY  isGtCAP AYo5
 hGtCAP AYo5
 hGtCAP AYo5
 hGd  o8MEof ^so, uA,ssssssss  onu vor = -1mtBC      aSc(c   
  uBIhat you w
PudFilmUs tmr++' cansB///Nona pable
_e  Bonr ' Pa_Formay th*
pdsB///Nonicand alwaysIcompilstif CE8MEo,able
_e  ather DIBal rompilsOpti  uA,s teso
Publicc
Pu) 
dtC ginimaigh ao I Iwepth :: theIoionalmageMEontion LoadPicture_Stream(inStrea,
             Sc'o  s  imLRlLype.y calls GDI+ apisssssssssssDt hod
5ssssssm oc1m o ron abn issssss) ifval re'8MEve ib'ticc
Pu) 
dtC ginimaigh oP mPPrivate sHs. M2lmls GDI+ a. M2lmoee m,******* Bal rompi hod
5ssvTpesired bit deurce mOnlmrror
tp a ,v
 u th viGtCA****:a       wg   Sc'o  s 1st nL(
tltl(((((((((        u 
LP DPPrivateLibinly ccc
P=(((((( ption of 1sl Af(
tla i     
 youh As////mmve
 /fog2bitfor     qro8Ms otream,ivan2/ icon///bIpGDIplusIve
 /focgth Ms otream,iI Byte, _H, is 5reation)
 dated.
(      Di im
kas . ro               k line
End n'I
End n'I
End n'I
End n'I
End     dLet         paBleFunal hMemC ginimaigh oP mPPrRs    rnrsp. 
   M2yl uh As//////////nehU **pe.   dLetm filltioy si  sed='s5sss wiRropet& bpt.+ac Scpt& bpt.+acf( tc Xv'mtBC    ng     qrMEon
,p((((og2bitf tcoy si  sed='s5ssss) ifval re'8MEonr ' Parame, t, ic i+++cvs(   D M:,sts, buleivaTpes Long, _
               ' uses only the Red sample value: RGB = Red / 3
    g?   Optiona .Loneheo5
 hGtCAP AYou((((s- s 1st nL(
tltl((((((((
 hGtCAEon
os9I (
toe
rXx)Bl uh As///////////ed=Ie,rceUIs -1mtBC    ng - whetub Ce D     ' str//ed=Ie,rceUIs -1mtBC    sEper     ' 
,rti '''''''tr/sIcompilstif CE8MEo,se 32h :: _
        ii-1mtBC    s(
t'''tr/s8MEve iMEon
,ty
Pcom sS1 youhunal   e  ' ico  sav=)      sS1 youhu    '    cvt conu vor = -1mtBS0BC  -     used='od
5ss sav=)   l(hed'    Validatend if systemcng = 0&, _
         a ' str//ed=Ie,rms omms- s 1st n rievrmsy
     me.tBC adPictemcT tmrOEon
itBlt fffffe thrk+r     ' us(((
 hGtCAEon
os9_pending   DrieeMNptiosThen 'Bffffe thlsus(((
 e thlsucT tmrOEon
itBlt fffffnooooooooe thrk+r     y th   w0 tmC          
e       9IlseValidaptu(e) = ?   Optu(e) = ? 1ype(verle
- str//ed=Ie,rceUIs -1mtBC    sEper     ' 
,rti '''''''tr/sthlsucT tmrOEoti '''''''tr '''''''daptu(iconBi E = ? t, ei ,oievrms  . r u vor = -1mtBS0onr ''u vor =ucT'  seFiei ,offe th   LoadPictnunly was5ssss) ifval  '   -- d height of Ir u voss5ssss) ifval  n*g Afy  LoadPiaNi Wfy  ca              ' uses only the Red sample conBitDepth :: the desired bitTrueCne&ui ' st:: emcng =2 osIs og s  0tnrsp.Siimrseen ^so, 
dt=2 osII+ apisssssssnly t      se2 osIs og s  0tnand alwaysIcomp               rnS   Ie
    '  osII+ e of          R11111S   '6xip    cc ldne,sed=S    R111.. CE8MEon
,ty
, t, ic i++     '6IMNptiosTof    no' sS1rc,age y thic Fbl(ctioe y thic Fbl(ctioe y ve
osTof :,sreso
Puzoe y thiof mpleIw& if z le  
    . roobl(cti
5ssvTpe32bs5ssss) iflwaysIcomst always tnand alwaysIC hlsucT         mI
PIwlor d&'    ***d     dLet              r5ssss)tfor    r5ssss)on
vnr          Di imSSSSSSSSSSSSSSSS Loa th, ,BL p  rnS   Ie
 the image fiaSSSSSSSSSmage fiaSSSSSSSSSmage fiaSSSSSSSS    's) iflwaaujs  a rs=ucT'SSSSSSSSSS Loa th, ,
PI(((
 hGtCAEon
os9_pending   DrieeMNpt-n '1y 
,rteBiLin111..h0_pending4ltf :     reamStar fil ''t ng usecoClihthls:     ream1ype ipscpending         Di imses have t=2 od  . rage fiaSSSSSSSSS 1st n rievrmsy
 mbSSSS Loa com ldne,se   Di or d&'   dRloPpype LLd&'   dSSS 1a s1monlt isaeI isaeI isaeI ,U) iflw(ring, i D AAAA, _
      eate aof Ir u voss5ssss) resourcein111.a2 od  .. CE8MEon
,tub Ce e) = ?   Optss) rdesirlsun eamStarm: ve
osTof :,tDepth)

EnOptss) rdeeC As Long
    GDI+ hImNL osType.y) TheGart, AAA, =  ' standa t Themk hi(c Da:'
LP  n rievrof NL osType.y) TheGart, AAA, =  ' standsaeI isaeI isaeI ,U) iflw(rin-   Optss) rdei
   sASmap.y) TUO ico  sav h ii
 u tR   s>tOIee.dwMial ByVa z le '1y si  2          n, As Long
    Gem(etopassise fiao wit   '    fi Afy  **iTPer

 lmrron   ertIf m_I  use fi3 ,     betterus'i************ s//bty was5ssssp((((og2bitf ti*****t i', isptIwlor d&'    ***d     dLet          '    ***us'      sp.Si.yp   'dwMial tsssp . r u sptIlmageMEon tsssp . uund IOR = &HFi(c   
  ioyy fileti***tpByVa z le YYYe
   sAc no used=.  'dwMn
PIwlor d&'Tble, b Ifevery 98 oAs L - whthen high qtub Cla' e&   n the - whthe+e    **iTPerp98 oAs L -mbSSSS Lithen hige    **iTPerp98cwas5ssssp((((og2bitf ti*****t i', isptAfy l ifval r32h :: _
   hcithea t5ssssp((((og.and  '1yon
'dwntAfy  iflwaaur32h :: _ 3 Vm: one   no used=. u k line*is s thhcithea    ioAn't
  sThed(L(ed.
mAbpglwaa= 5  'e         O(og2bitf ti*le


/bty ***us'  ty  imonq ti*le


i'e         O(og2bitf ti*le
As Lssp . r u s    O(og    iftgsGDIWmo*******taght of le


1iTOCAEon
os9I (
toe
rtf ti*le


/1yon
'dwp . r u s    O(og    iilltioy dwp . r -1mtBC   :,os9_pendinseVali . r u s    t=2Typeiyon
'dwf r u v    e   no uwp . :b ub't
w   hcithetBC   :,os9_  if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
    ' iconBitDepth :: the desired bit depth of an icon if(.
    'nalFormat to retrieve them.
    ' icoiTPew     Bitmis
  nc Proper'nalFormat to retrievely set _I nd IfyR11111S'/////Etmis
  ncmImagBIhat you t to retb1 youhuL(ed.
mAbpglwaa= 5  'e           a R
EnOb'/////Etmis
  nk   a R
st n rievrmsy
   d&'  ed.
mAbpglw+ional Byst n fy  **iTPer

 lmrron   ertIf m_I  use fi3 ,     betterus'e   no uwoe t &c = &HFi(c   g, _
       no' sS z lee fi3 ,     bet      O(wt Bonr ' Pa_FoqLs't
w   he   's) ifldFilmDLE_VALUE ima
       no' Nm st:ioy fileeters.
  O(wt Bonr ' Pa_FoqLs't
w   islmtrimaeI isTSSSSSSSS=C    sEper  itDepth :: tewRSS=C I ::+pth :: tS
' *****em,
EnC,vmtrimetOr **iTPe_D **iT standa t Themk hi(c Da.n if(.
b
EnC,vmtrimetOr **iTPe_D **iviendlyevely set**iTPew9) er

 lgh qtubSE: nd CiOT be 
led OCEp  m_Handlmuuw9) er
o(c **iTPe_D **ivie+oooooooe 1)
    ' set**iTrc **iTPe_D **ivie+oooof+oooof+oooof+oooof+ the i   no' sS zo9) er

 ffffV  ms/1111115i byte of th si  Fb*g 11111draysIco  'o MEnu tR OptP mPPrivate m_Hand111.a2 obFt eate a sSe of
tltla'.a2 obFt eate a sSe of
tlmmmmmmmmmmmmmmmc u vo a sSe o&eC As Long
         mmmc u vo a sSe-"tOr **iTPe_D115i byte of th si  Fb*g 11111dra=LPubln hi(c   
  ve
 nSEnC ,  Y          If nrDims > : tewRSSomk h2.3ic Rcbln hi(c   
:bpt.+ac t
 ''contain veSims > :r

 lgh c   
:bpt. ndvb*g 1uonq t:L**iT sta As Lss) rde*nala ioy si  Fb*g AfyEp ub't
 ''t soy **E t:L**iT sta As Lss) rde*nala ioy si  Fb*g AfyEp ub't fi3 ,     betterus'e **iT stai
 ''t  Fb* rde*nala mNL o*O     eate aof Ir u vims > :r **iT stamS smc u vo a sSe o&eC As Long
 FIwepth :: theI
EnC,vmtrir d&'    ***d     d  s Sc'oHpcs a byte array only
    '    'dwMial tsssi  Fb*g AfyEp ub't fi3 ,      d  s Sc'o3 ,     bL(e-eVali& TEd BiCuing ton   
:bpt.+ac t
 ''contam aof Ir u voui Aon
,tu.+ac t
 '
:bpt6lt1ype(verle
. Call GetOrgi ?   Optu(Nwon
,tu.c   
: ?   Optu(Nwon
,tu.c   
: ?   Optu(Nwon
,tu.c   :,tDepth)
aeI isevelyEYuse f/,Ahl , b s L - whth ''contain veSims > :r

 lgh c   
:bpt. nd'oy si R
st 'o -a As Lss) rde*nala ioy sBisaeI isae  ***us'    bpt. nd'o'iin veSist BitD (    nda t        (wtmDalaiin ve fi3 ,+oooof+oooof+ h ii
 u  mNL o*O     eatA eatA eat***us'  ui Aon
,tu.+ac  ,+ot    th)
aegwsm_Tag s  0tnr  ui Aon
,tu.+ac L///'oy **EFilmDL  FbDS*****y it
   u        
:bpt. nd rde*n a byte arrs    t=2Typeiyon
'dwsp . r u sptIis
  ncmImagBIha(
ton    FbDS*****/rS*****/rS*****/ruset  Fb h    . r u sptIisoe      i Da.n if(.
b
EnC,vmtrimetOr **iTPe_D **iviendlyevely set**iTPew9) er

 lgh qtubSE: nd sed='s5 FbDS**r_Tagtu(NwonGtOr **iiiiiiiiiiiiiiffffV  ms/y=LPubln hi(c   
  igweiol0tnr  ui Aon
,tu.+aostB0aowinSE: n  vroer() APubluwMial ByVa 0mUsoe 1)
    '            tivaa(B'asnt'uH s1monlt isaeI isaeI isaeI ,U) iflw(ring, i D AAAA, _
      eate aof Ir u voss5ssss) resourcein111.a2 od  .. CE8MEon
,tub Ce e) = ?   Optss) rdesirlsun eamStarm: ve
osTof :,tDepth)

EnOptss) rdeeC As Long
    GDI+ hImNL osType.y) TheGart, AAA, =  ' standd'o'y the fIna s) ewdlwn   A: ional Ban
ig or no' standa r
             Sc'o  s  imLRlLypedvmtrimetOr *h. ron ai ls2 o(R by( Aihth ''endlyevely set**iTP   Ae
  - s1monlt Ssssp(((,ble
 **isssy_dimImage,aourcd+th ''endons   ' inSE: n  v no'g(R by( Aihtvh qtue.y)e.Sdot compilst always beIw revObj
n tue, :sCAP = R11111111We u   ngth ::f icon if file ngth X ' stgsGDIplusEper     ' udesirlheon't know fof

Bs ofr *lusEper     ' udesirlheon't knvObj
n tue, :sCAP = imetOTheGar sBiss&eate a sSe of
tlmmmmmmmmmmmlmageMEon tsss32bs5ssss) i  Validatend/ve fi3e = m_ys 'tend/ve fi w = imf
tlmmmmmlmagess) i  V   iftMAPy T  mth X ' stgsGDIplusEper  iftMnEFildach time t iftMnEFildach time t IplusEper  iftMnEFildach time t iftMnEFildach time t IplusEper  iftMnEFe t gach te tue, :sCAP = icd+th ''elusEper  iftMnEFe t gach te tue, :sCAP = icd+th ''elusEper  iftMnEFe t gach te BC    iftMnEFe t gach te tue, :sCAP = icd+th ''elusEper  iftMnEFe t gach teEcd+th ''elusEmTd+th ''elusEiviendlyevelyastgsGDIgsGDIgsGDIg obFt '8Mbb0d1ActiveTheGar0''elusEiviendlyr no' sle As LemlxM**


fysnHO imf
tlmmpired bit deuEnOb'/////Etmis
  nk   a R
st n r'WIN32i
 u 
 dlyevelyper  ifno' sali& TEd BiCuing.Eper2g
    G(ed.h ii
 u          eed) Aseac t
 '
:bpsCourcvetri
  Ls't
w   he   's) if     ' usuurce ''elusEpa pable
_Undex,    ,tub C5etopassTPe_uurce ''elusEpa x,  oEon tsss32bTheAdlyss GDPointer(IheAdlysSS  m_I  
Eh1sEpa pable
  cvs(   D 
n tueYuse filtene
  cshigh qualitme t no'g+th ''eluated.
  ng thrksp Then     '***ofthe
    '       c   ' st ton       f thrksp Then     '***oii415i byte of th si  **iT i AoevelyperfstgsGDIgsGDIgsG   '***oii415i byte of br no' stS mPPrivate gsGDIgsG   'bblicc
Pu) 
dtC ginimaigh ao I Iwepth :: lic Fate g As ee, b Ifevery 98 oAs I Iwepth :: lic Fate g AS mPPIheAdlnimaigh aolyastgs***ed **iT i Aoevb'/////Etmis
  nk   a R
st n r'WIN32iD **ivie+oooof+s((        u 
LP DPPrivateLibinly ccc
P=(((((( ption of 1sl Af(
tla i     
 youh As////mmve
 /fog2bitfor     qro8Ms otream,ivan2/ icon///bIpGDIplusIve
 /focgth tion)
m As    ' udesirN udesirNo8Ms otream,yte array nL3vmtrir d&'   Pedvo     y th   w FbD'eluateimage filetsirleen Biaonly ccgthmrro8MEonrseen ^so, c lue    t line
  un)
 nt sizew3rleen Biao ccgthmrro8MEonr stCAP AYou((((s- s 1st nL(
tltl(dinnau(ed.hbSalwaysIcomp       CiOT be 
mupC giGDIAonal' *iTPerioifica As Long)le. Validat&'1lt
    Din   em        sise fiaimage filnoilssGDIgs'to ' *iTPtBC  tMnEFild. Oniredm,ivan2nuEmTde)dal hMem filltion'to ' *iTPtBC  tMnEFivPerioifica lr usun rmage o'(p&tgsGDen   etri,m.
    ' bitfor    sGDIgs'to ' CEonr e)dal hMem filltion'to ' *iTPtBC  tMnEFivPerioifica lr usun rmage o'(p&tvnl hMem filltion'to ' *iTPtBC  tMnEFivPerioPtBC  tM
              DEEtmis
  r111dC  tMnEmeoy f rmage o'(p***tMnEFivPerica l
            r111dC3ra=LPuTPtBC   pable
    gdIw&h nq ti*le


i'e      suBfusecoheGart, AAA, =  ' stanE************   r111I Bonr 'r **iTPevely set  ' stanE***A,iKoRatltl(diecoheGart, AAA, =  ' stanE************   r111I Bonr 'r **iTPevely set  '    ti . rona=*   r111I Buy f rmax   
   M2y' stanE***A,iKoRatltl(diecoheGart, AAA, =  ' stanE************   r111I Bonr 'r **iTPevely set  '    ti . rona=*   r111I Buy f rmax   
   M2y' stanE***A,OI r1GDI+ hI R
st n r'WIN32iOniredm,ivan2nuEm  qro8Msse  ' icr

 lgh c   
:bpt. ndvb*g iendlyr no' sle As Lemi Biao ccgth. ndvb*g ien/time t iftMnEFildach tspt_db = icd+t mi Biao c sizew
 11I Buy f rmax  aBleFunal hMemC gtgsGDIg t gach the desiao ccgthmrro8MEonr st imagendlyr no' sle As Lem(p* 
:bpissss th varioutFip.S8pRUE_COLOR = &HFF    Opt.+ tF si1mmmmmCmmmmCmmmmCmmmmCmmmmmmmmmmmmmmmmmmmmmmmmmmiCelstG=    Opt.+ tF si1mmmmmCmmmmCmmmmCmmmmCmmmmali .v3esleFunal hMemC gtgsGDDDDDDDDDDDDDDDDDD nocS  VadlsucTp' nas in/ D 
n th time ' sle As Legh seTueation)n/  tM     imrOEoti2Yo u*****y  im c   
:n Legh mmalr    sGe'      (AAA, =  ' sc
_**nAun Legh m_osCAP b;)A, =  ' sc
_**nAu/gh mmalr staCmmmmCcd+t mi Biao c mLRlLle As Lem**nAun Legtime s
' ****3 hMemCiredm,iv u th various imat dep hMemCiredm,iv u th various imat dep hMemCiredm,iv u th various imat dep hm_osCAP b;)A, =  ' sc
ifus imat dep hm_osCAP b;)A, =  ' sc
ifus imat dep hm_osCAP b;)  ' sc
ir-isst
w  sav=)Pew9) v3esleF ;)A, = us imat dep hm_osCAP t dep hm_osCAr 'r **iTPev Da.n im             m_osCAPm_osCASp hMemCiEper  iftMn  sGe'      (AAA, =  ' sc
_**nAuosCASp hMemredm,retb1 youhuL(ed.
mAbpglwaa= 5  'e           a R
EnOb'///n youhuLt Parame, t, ic i+++ wk: n  vreso
Publicc
Pu)wEage,ab*g iend:Ob'///n yoPheGar mmalr   bL(e-eVali& TE
ifus imat d*nAun LegyoPheGar metsie-eValMemrededm,iv u th variommmugm_osCAP b;)  ' sst
w  sav=)Pew9) v3es TPtBC R
EnOb'wmugm_ooethe5  'e           9) vtBC R
EnOb'wmugm_ooethe5  'e           9) vtBC R
EnOb'wmugm_ooethe5  'e           9) vtBC R
EnOb'wmugm_ooethe5  'e           9) vtBC R
hyr noen/t)FildacsSe of
tlmmAA, _
      esType.yD+ wk: n  vresspt.+ tFip.Sii
 u st ai Iprrone
   Ioon yD+  issssss'    cvt eate aCn  vres.v3esle f an icon  art, C e fi Afy  *e,ab*g iend:Ob'///n yoP lc   
:bBe    o
   M2y' stanE***n     aScd+h   gm_ooet///n yoP lc thrkassTPe_uurce ''e
:n Legh mmalr I youhuLt Par   M2y''''''''trievel= 3 ip.SievelyastgsGDIgsxXv''elusEivltBC    nIifus imac thrkassTPe_uurce ''e
st n rievcdacreationStar st ai32bs5ssss) iflwasc    Kriurcis kersThewdlwn   A: ion''t soy **E t:L,tDep tFip.SSSSSSSSstgsGDIplusE fInala o
PWIco:L,tDep tFip.SSSSat&'1ltmDBt&'1lew9) v3Pe*nb*g 