Home > Software engineering >  Here is to obtain the image color, width and height of a program, who can explain the way of thinkin
Here is to obtain the image color, width and height of a program, who can explain the way of thinkin

Time:10-05

API desperately learn no
'the API statement
Private DeclareFunction GetObject Lib "gdi32" Alias "GetObjectA" (ByValhObject As Long, ByVal nCount As Long, lpObject As Any) As Long 'to get information of the specified graphics object
Private DeclareFunction GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByValdwCount As Long, lpBits As Any) As Long 'previous location map of a copy into the buffer
Private TypeBITMAP 'Bitmap's statement, don't need to understand
BmType As Long
BmWidth As Long
BmHeight As Long
BmWidthBytes As Long
BmPlanes As Integer
BmBitsPixel As Integer
BmBits As Long
End Type
Dim hBitmap AsLong
Dim res As Long
Dim As BMP BITMAP
Dim byteBry () define an array As Byte '
Dim totbyte As Long, As Long I
HBitmap=SrcPic. Picture. Handle
Res=GetObject (hBitmap, Len (BMP), BMP) 'get the BitMap structure
Totbyte=BMP. BmWidthBytes * BMP. BmHeight 'how much in total Byte to save figure
ReDim byteBry (totbyte - 1)
'to redefine the arrayRes=GetBitmapBits (hBitmap, totbyte byteBry (0))
in the 'put the graph in byteBryList1. AddItem "image Bits:" + CStr (BMP) bmBitsPixel) 'each pixel of a
List1. AddItem "picture height:" + CStr (BMP) bmHeight) 'original high
List1. AddItem "image width:" + CStr (BMP. BmWidth) 'artwork

CodePudding user response:

Master? Great god? Where is it?

CodePudding user response:

The format of the BITMAP file header has a regulation, which is defined in BITMAP type, this type is the male version of Microsoft's API interface type, the prototype is:
The Public Type BITMAP '14 bytes
BmType As Long
BmWidth As Long
BmHeight As Long
BmWidthBytes As Long
BmPlanes As Integer
BmBitsPixel As Integer
BmBits As Long
End Type

Note that private TypeBITMAP should be private Type BITMAP (note space),

GetObject is an API function:
Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

It can be in accordance with the specified object handle to obtain BITMAP from the object type information,

GetBitmapBits is another API function:
Public Declare Function GetBitmapBits Lib "gdi32" Alias "GetBitmapBits (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

It can retrieve the object pixels,

CodePudding user response:

The building code does not get the bitmap information,

CodePudding user response:

Slavish...

CodePudding user response:

If you want to get only the BMP format of image information, I have here a complete sample may be more clear,
Use the BMP file complete file header information:

The Public Type bmpHead
BmpFlg1 As Byte '1 + 0=1 "B"
BmpFlg2 As Byte '1 + 1=2 "M"
FileSize As Long '4 + 2=6' file length
Reserved1 As Integer '2 + 6=8' reserves (==0)
Reserved2 As Integer '2 + 8=10' reserves (==0)
BmpDataOffset As Long '4 + 10=14' image pixel encoding data migration
BmpInfoSize As Long '4 + 14=18' basic information image bytes
BmpWidth As Long '4 + 18=22' image width
BmpHeight As Long '4 + 22=26' image high
BmpPlanes As Integer '2 + 26=28' palette layer
PixelBits As Integer '2 + 28=30 each pixel corresponding bit number
Compression will As Long '4 + 30=34' Compression mode (0=uncompressed)
BmpDataSize As Long '4 + 34=38' image data bytes
XPelsPerM As Long '4 + 38=42' resolution X
YPelsPerM As Long '4 +=42 46 Y resolution
UsedColor As Long '4 + 46=50' time to use the color of the number of
ImportColor As Long '4 + 50=54 shows important color count
End Type
  •  Tags:  
  • API
  • Related