c32bppdib.cls
来自「AeroSuite--一组非常漂亮的VISTA控件集」· CLS 代码 · 共 1,364 行 · 第 1/5 页
CLS
1,364 行
txtTitle = 1 ' See cPNGwriter.SetPngProperty for more information
txtAuthor = 2
txtDescription = 4
txtCopyright = 8
txtCreationTime = 16
txtSoftware = 32
txtDisclaimer = 64
txtWarning = 128
txtSource = 256
txtComment = 512
' special properties
txtLargeBlockText = 1024 ' this is free-form text can be of any length & contain most any characters
dateTimeModified = 2048 ' date/time of the last image modification (not the time of initial image creation)
colorDefaultBkg = 4096 ' default background color to use if PNG viewer does not do transparency
filterType = 8192 ' one of the eFilterMethods values
ClearAllProperties = -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 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
TRUE_COLOR = &HFF000000
HIGH_COLOR = &HFFFF00
TRUE_COLOR_ALPHA = &HFFFFFFFF
End Enum
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 Long ' See Class_Initialize
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
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 24) = 8))
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 = 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.
If iparseIsArrayEmpty(VarPtrArray(inStream)) = 0& 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 = 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) 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 storing these in "Custom"
' 3) All other types of images are normally stored in the "Custom" section
On Error GoTo ExitRoutine
Dim oWorkSpace As VB.Global, tPic As StdPicture
If VBglobal Is Nothing Then
Set oWorkSpace = VB.Global
ElseIf TypeOf VBglobal Is VB.Global Then
Set oWorkSpace = VBglobal
Else
Set oWorkSpace = VB.Global
End If
If VarType(ResSection) = vbString Then
Dim inStream() As Byte
' could be anything, PNG,icon,gif,32bpp bitmap,wmf, etc
inStream = oWorkSpace.LoadResData(ResIndex, ResSection)
LoadPicture_Resource = LoadPicture_Stream(inStream, iconCx, iconCy, streamStart, streamLength, , iconBitDepth)
Else
' can only be single icon, bitmap or cursor
Set tPic = oWorkSpace.LoadResPicture(ResIndex, ResSection)
LoadPicture_StdPicture tPic
End If
LoadPicture_Resource = Not (m_Handle = 0&)
ExitRoutine:
If Err Then Err.Clear
End Function
Public Function LoadPicture_StdPicture(Picture As StdPicture) As Boolean
' PURPOSE: Convert passed stdPicture into a 32bpp image
' Revised to allow 32bpp stdPicture objects which can be loaded
Me.DestroyDIB
If Not Picture Is Nothing Then
' simply pass off to other parsers
If Picture.Type = vbPicTypeIcon Then
' pass to icon/cursor parser
Dim cICO As New cICOparser
Call cICO.ConvertstdPicTo32bpp(Picture.Handle, Me)
Set cICO = Nothing
ElseIf Not Picture.Type = vbPicTypeNone Then
' pass to bmp,jpg,wmf parser
' Note: transparent GIFs should not be passed as stdPictures
' Pass transparent GIFs by Stream or FileName
Dim cBMP As New cBMPparser
If Picture.Type = vbPicTypeBitmap Then
' pass by handle to ensure 32bpp stdPicture objects are processed correctly
Call cBMP.ConvertstdPicTo32bpp(Nothing, Picture.Handle, Me, 0&)
Else ' probably wmf/emf, pass by stdPicture
Call cBMP.ConvertstdPicTo32bpp(Picture, 0&, Me, 0&)
End If
Set cBMP = Nothing
End If
LoadPicture_StdPicture = Not (m_Handle = 0&)
End If
End Function
Public Function LoadPicture_ByHandle(Handle As Long) As Boolean
' PURPOSE: Convert passed image handle into a 32bpp image
' Revised. Previously, I cheated by creating a stdPicture from the handle
' then used existing LoadPicture_stdPicture to process. This had
' the nasty side effect of not processing 32bpp images correctly
' if they were loaded from LoadImage API
Dim icoInfo As ICONINFO, tPic As StdPicture
DestroyDIB
If Not Handle = 0& Then
Select Case GetObjectType(Handle)
Case OBJ_BITMAP
' process bitmaps by handle
Dim cBMP As New cBMPparser
LoadPicture_ByHandle = cBMP.ConvertstdPicTo32bpp(Nothing, Handle, Me, 0&)
Case OBJ_METAFILE, OBJ_ENHMETAFILE
' we should be able to convert this to a stdPicture...
' Really don't want to mess with metafile DCs if I don't have to
Set tPic = iparseHandleToStdPicture(Handle, vbPicTypeBitmap)
If Not tPic Is Nothing Then
' send to this routine to process
LoadPicture_ByHandle = LoadPicture_StdPicture(tPic)
End If
Case Else
' Test for icons & cursors
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?