Get information about bitmap file

zhaozj2021-02-11  197

Add a Picture control and a CommandButton control in the Form, add a bitmap file in the Picture control, add the following code:

Private Declare Function GetObject Lib "gdi32" Alias ​​"GetObjectA" _ (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) _As LongPrivate Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, _ByVal dwCount As Long, lpBits As Any) As LongPrivate Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As LongEnd TypePrivate Sub Command1_Click () Dim hBitmap As Long Dim res As Long Dim bmp As BITMAP Dim byteAry () As Byte DIM TOTBYTE As Long, I as long hbitmap = Picture1.Picture.Handle Res = getObject (HbitMap, Len (BMP), BMP)

'Structure of Bitmap

Totbyte = bmp.bmwidthbytes * bmp.bmheight

'How much is a total of Byte?

Redim Byteary (Totbyte - 1)

'Saves information in Picture1 to Byteary

Res = getBitmapbits (Hbitmap, Totbyte, Byteary (0)) Debug.print "Total BYTES COPIED:"; res debug.print "bmp.bmbits"; bmp.bmbits debug.print "bmp.bmbitspixel"; bmp.bmbitspixel

'

Debug.print "bmp.bmheight"; bmp.bmheight

'Calculate image height

Debug.print "bmp.bmplanes"; bmp.bmplanes debug.print "bmp.bmtype"; bmp.bmtype debug.print "bmp.bmwidth"; bmp.bmwidth

'Calculate graphics width

Debug.print "bmp.bmwidthbytes"; bmp.bmwidthbytes

'The length of each scan line calculated by byte

End Sub

转载请注明原文地址:https://www.9cbs.com/read-4041.html

New Post(0)