?? modbitmap.bas
字號:
Attribute VB_Name = "modBitmap"
Option Explicit
'========================================================================================================
'
' modBitmap Module
' ----------------
'
' Created By : Kevin Wilson
' http://w3.one.net/~kevinw/VB ( The VB Zone )
'
' Last Update : March 14, 2000
'
' VB Versions : 5.0 / 6.0
'
' Requires : NOTHING
'
' Description : This module is a collection of very useful functions designed for use with graphics
' manipulation. You can use it to find out information about pictures in memory, or to
' render such pictures on to specified Device Contexts (DC).
'
' If any of the functions in this module fail, you can most likely get extended error
' information by calling the "GetLastError" Win32 API function.
'
' Example Use :
'
' Dim TheHeight As Long
' Dim TheWidth As Long
'
' ' Show the form so you can see the drawing as it happens in debug mode (step by step)
' Show
'
' ' Make the picture redraw itself so it doesn't go away if the form loses focus
' Picture1.AutoRedraw = True
'
' ' Get the height/width in pixels
' If Convert_HM_PX(Picture.Height, Picture.Width, TheHeight, TheWidth, True) = True Then
'
' ' Draw the picture onto the PictureBox object called "Picture1" and
' ' invert the colors by specifying "SCRINVERT" as the raster operation
' ' instead of the default "SCRCOPY"
' If RenderBitmapEx(Picture1.hDC, , Picture.Handle, 0, 0, 0, 0, TheHeight, TheWidth, SRCINVERT, , , , True, Picture1.hWnd) = True Then
' Debug.Print "SUCCESS!"
' Else
' Debug.Print "FAILED!"
' End If
' End If
'
' ' Set the "Picture" property to equal the "Image" property
' Set Picture1.Picture = Picture1.Image
'
'========================================================================================================
' Type - General
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
' Type - General
Public Type POINTAPI
X As Long
Y As Long
End Type
' Type - GetEnhMetaFileHeader.lpEMH.(rclBounds/rclFrame)
Public Type RECTL
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
' Type - GetEnhMetaFileHeader.lpEMH.(szlDevice/szlMillimeters/szlMicrometers)
Public Type SIZEL
cX As Long
cY As Long
End Type
' Type - OleCreatePictureIndirect
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
' Type - OleCreatePictureIndirect / OleLoadPicture
Public Type PICTDESC_ALL
cbSizeOfStruct As Long 'UINT // Size of the PICTDESC structure.
PicType As Long 'UINT // Type of picture described by this structure, which can be any of the following values: PICTYPE_UNINITIALIZED, PICTYPE_NONE, PICTYPE_BITMAP, PICTYPE_METAFILE, PICTYPE_ICON, PICTYPE_ENHMETAFILE
hPicture As Long 'LPVLOID // Pointer to the bits that make up the picture. This varies depending on the type of picture (see following structures)
hPALETTE As Long 'HPALETTE // Pointer to the picture's palette (where applicable)
Reserved As Long ' // Reserved
End Type
' Type - OleCreatePictureIndirect / OleLoadPicture
Public Type PICTDESC_BMP 'picType = PICTYPE_BITMAP
cbSizeOfStruct As Long 'UINT // Size of the PICTDESC structure.
PicType As Long 'UINT // Type of picture described by this structure, which can be any of the following values: PICTYPE_UNINITIALIZED, PICTYPE_NONE, PICTYPE_BITMAP, PICTYPE_METAFILE, PICTYPE_ICON, PICTYPE_ENHMETAFILE
hBitmap As Long 'HBITMAP // The HBITMAP identifying the bitmap assigned to the picture object.
hPal As Long 'HPALETTE // The HPALETTE identifying the color palette for the bitmap.
End Type
' Type - OleCreatePictureIndirect / OleLoadPicture
Public Type PICTDESC_META 'picType = PICTYPE_METAFILE
cbSizeOfStruct As Long 'UINT // Size of the PICTDESC structure.
PicType As Long 'UINT // Type of picture described by this structure, which can be any of the following values: PICTYPE_UNINITIALIZED, PICTYPE_NONE, PICTYPE_BITMAP, PICTYPE_METAFILE, PICTYPE_ICON, PICTYPE_ENHMETAFILE
hMeta As Long 'HMETAFILE // The HMETAFILE handle identifying the metafile assigned to the picture object.
xExt As Long 'int // Horizontal extent of the metafile in HIMETRIC units.
yExt As Long 'int // Vertical extent of the metafile in HIMETRIC units.
End Type
' Type - OleCreatePictureIndirect / OleLoadPicture
Public Type PICTDESC_ICON 'picType = PICTYPE_ICON
cbSizeOfStruct As Long 'UINT // Size of the PICTDESC structure.
PicType As Long 'UINT // Type of picture described by this structure, which can be any of the following values: PICTYPE_UNINITIALIZED, PICTYPE_NONE, PICTYPE_BITMAP, PICTYPE_METAFILE, PICTYPE_ICON, PICTYPE_ENHMETAFILE
hIcon As Long 'HICON // The HICON identifying the icon assigned to the picture object.
End Type
' Type - OleCreatePictureIndirect / OleLoadPicture
Public Type PICTDESC_EMETA 'picType = PICTYPE_ENHMETAFILE
cbSizeOfStruct As Long 'UINT // Size of the PICTDESC structure.
PicType As Long 'UINT // Type of picture described by this structure, which can be any of the following values: PICTYPE_UNINITIALIZED, PICTYPE_NONE, PICTYPE_BITMAP, PICTYPE_METAFILE, PICTYPE_ICON, PICTYPE_ENHMETAFILE
hEMF As Long 'HENHMETAFILE // The HENHMETAFILE identifying the enhanced metafile to assign to the picture object.
End Type
' Type - GetObjectAPI.lpObject
Public Type BITMAP
bmType As Long 'LONG // Specifies the bitmap type. This member must be zero.
bmWidth As Long 'LONG // Specifies the width, in pixels, of the bitmap. The width must be greater than zero.
bmHeight As Long 'LONG // Specifies the height, in pixels, of the bitmap. The height must be greater than zero.
bmWidthBytes As Long 'LONG // Specifies the number of bytes in each scan line. This value must be divisible by 2, because Windows assumes that the bit values of a bitmap form an array that is word aligned.
bmPlanes As Integer 'WORD // Specifies the count of color planes.
bmBitsPixel As Integer 'WORD // Specifies the number of bits required to indicate the color of a pixel.
bmBits As Long 'LPVOID // Points to the location of the bit values for the bitmap. The bmBits member must be a long pointer to an array of character (1-byte) values.
End Type
' Type - CreateIconIndirect / GetIconInfo
Public Type ICONINFO
fIcon As Long 'BOOL // Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies an icon; FALSE specifies a cursor.
xHotspot As Long 'DWORD // Specifies the x-coordinate of a cursor抯 hot spot. If this structure defines an icon, the hot spot is always in the center of the icon, and this member is ignored.
yHotspot As Long 'DWORD // Specifies the y-coordinate of the cursor抯 hot spot. If this structure defines an icon, the hot spot is always in the center of the icon, and this member is ignored.
hbmMask As Long 'HBITMAP // Specifies the icon bitmask bitmap. If this structure defines a black and white icon, this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If this structure defines a color icon, this mask only defines the AND bitmask of the icon.
hbmColor As Long 'HBITMAP // Identifies the icon color bitmap. This member can be optional if this structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND flag to the destination; subsequently, the color bitmap is applied (using XOR) to the destination by using the SRCINVERT flag.
End Type
' Type - GetEnhMetaFileHeader.lpEMH
Public Type ENHMETAHEADER
iType As Long 'DWORD // Specifies the record type. This member must specify the value assigned to the EMR_HEADER constant.
nSize As Long 'DWORD // Specifies the structure size, in bytes.
rclBounds As RECTL 'RECTL // Specifies the dimensions, in device units, of the smallest rectangle that can be drawn around the picture stored in the metafile. This rectangle is supplied by graphics device interface (GDI). Its dimensions include the right and bottom edges.
rclFrame As RECTL 'RECTL // Specifies the dimensions, in .01 millimeter units, of a rectangle that surrounds the picture stored in the metafile. This rectangle must be supplied by the application that creates the metafile. Its dimensions include the right and bottom edges.
dSignature As Long 'DWORD // Specifies a double word signature. This member must specify the value assigned to the ENHMETA_SIGNATURE constant.
nVersion As Long 'DWORD // Specifies the metafile version. The current version value is 0x10000.
nBytes As Long 'DWORD // Specifies the size of the enhanced metafile, in bytes.
nRecords As Long 'DWORD // Specifies the number of records in the enhanced metafile.
nHandles As Integer 'WORD // Specifies the number of handles in the enhanced-metafile handle table. (Index zero in this table is reserved.)
sReserved As Integer 'WORD // Reserved; must be zero.
nDescription As Long 'DWORD // Specifies the number of characters in the array that contains the description of the enhanced metafile's contents. This member should be set to zero if the enhanced metafile does not contain a description string.
offDescription As Long 'DWORD // Specifies the offset from the beginning of the ENHMETAHEADER structure to the array that contains the description of the enhanced metafile's contents. This member should be set to zero if the enhanced metafile does not contain a description string.
nPalEntries As Long 'DWORD // Specifies the number of entries in the enhanced metafile's palette.
szlDevice As SIZEL 'SIZEL // Specifies the resolution of the reference device, in pixels.
szlMillimeters As SIZEL 'SIZEL // Specifies the resolution of the reference device, in millimeters.
cbPixelFormat As Long 'DWORD // Windows 95/98, Windows NT4.0 and later: Specifies the size of the last recorded pixel format in a metafile. If a pixel format is set in a reference DC at the start of recording, cbPixelFormat is set to the size of the PIXELFORMATDESCRIPTOR. When no pixel format is set when a metafile is recorded, this member is set to zero. If more than a single pixel format is set, the header points to the last pixel format.
offPixelFormat As Long 'DWORD // Windows 95/98, Windows NT4.0 and later: Specifies the offset of pixel format used when recording a metafile. If a pixel format is set in a reference DC at the start of recording or during recording, offPixelFormat is set to the offset of the PIXELFORMATDESCRIPTOR in the metafile. If no pixel format is set when a metafile is recorded, this member is set to zero. If more than a single pixel format is set, the header points to the last pixel format.
bOpenGL As Long 'DWORD // Windows 95/98, Windows NT4.0 and later: Specifies whether any OpenGL records are present in a metafile. bOpenGL is a simple Boolean flag that you can use to determine whether an enhanced metafile requires OpenGL handling. When a metafile contains OpenGL records, bOpenGL is TRUE; otherwise it is FALSE.
' szlMicrometers As SIZEL 'SIZEL // Windows 98, Windows 2000 : Size of the reference device in micrometers.
End Type
' Constants - BitBlt.dwRop
Public Enum RasterOperations
SRCCOPY = &HCC0020 ' Copies the source rectangle directly to the destination rectangle.
SRCPAINT = &HEE0086 ' Combines the colors of the source and destination rectangles by using the Boolean OR operator.
SRCAND = &H8800C6 ' Combines the colors of the source and destination rectangles by using the Boolean AND operator.
SRCINVERT = &H660046 ' Combines the colors of the source and destination rectangles by using the Boolean XOR operator.
SRCERASE = &H440328 ' Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
NOTSRCCOPY = &H330008 ' Copies the inverted source rectangle to the destination.
NOTSRCERASE = &H1100A6 ' Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
MERGECOPY = &HC000CA ' Merges the colors of the source rectangle with the brush currently selected in hdcDest, by using the Boolean AND operator.
MERGEPAINT = &HBB0226 ' Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
PATCOPY = &HF00021 ' Copies the brush currently selected in hdcDest, into the destination bitmap.
PATPAINT = &HFB0A09 ' Combines the colors of the brush currently selected in hdcDest, with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
PATINVERT = &H5A0049 ' Combines the colors of the brush currently selected in hdcDest, with the colors of the destination rectangle by using the Boolean XOR operator.
DSTINVERT = &H550009 ' Inverts the destination rectangle.
BLACKNESS = &H42 ' Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
WHITENESS = &HFF0062 ' Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)
NOMIRRORBITMAP = &H80000000 ' Windows 98, Windows 2000: Prevents the bitmap from being mirrored.
CAPTUREBLT = &H40000000 ' Windows 98, Windows 2000: Includes any windows that are layered on top of your window in the resulting image. By default, the image only contains your window.
End Enum
' Constants - LoadResData
Public Enum ResTypes
rt_Bitmap = vbResBitmap
rt_Icon = vbResIcon
rt_Cursor = vbResCursor
rt_Custom = 3
End Enum
' Constants - BITMAP.bmType & CopyImage.uType
Public Enum PictureTypes
IMAGE_BITMAP = 0
IMAGE_CURSOR = 1
IMAGE_ICON = 2
IMAGE_ENHMETAFILE = 3
End Enum
' Constants - General
Public Const MAX_PATH = 260
' Constants - ENHMETAHEADER.iType
Public Const EMR_HEADER = 1
' Constants - ENHMETAHEADER.dSignature
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -