# Re: 如何得到bmp的资讯？？

Posted by Honey on March 18, 1999 at 22:51:15:

In Reply to: 如何得到bmp的资讯？？ posted by 索尔 on March 18, 1999 at 03:48:32:

使用BITMAPINFOHEADER及BITMAPFILEHEADER
两个'类型'
宣告方式如下

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 BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type

之后可用以下方法取得结构
Dim BFH As BITMAPFILEHEADER
Dim BIH As BITMAPINFOHEADER
Open StrFileName For Binary Access Read As #1
Get #1, , BFH
Get #1, , BIH
Close

关于BITMAPFILEHEADER结构的值代表如下
bfType
Specifies the file type.
It must be BM.
bfSize
Specifies the size,
in bytes, of the bitmap file.

bfReserved1
Reserved; must be zero.

bfReserved2
Reserved; must be zero.

bfOffBits
Specifies the offset, in bytes,
from the BITMAPFILEHEADER structure
to the bitmap bits.

关于BITMAPINFOHEADER结构的值代表如下
biSize
Specifies the number of bytes required by
the structure.

biWidth
Specifies the width of the bitmap, in pixels.

biHeight
Specifies the height of the bitmap, in pixels.
If biHeight is positive, the bitmap is a bottom-up
DIB and its origin is the lower left corner. If
biHeight is negative, the bitmap is a top-down DIB
and its origin is the upper left corner.

biPlanes
Specifies the number of planes for the target device.
This value must be set to 1.

biBitCount
Specifies the number of bits per pixel.
This value must be 1, 4, 8, 16, 24, or 32.

biCompression
Specifies the type of compression for a compressed
bottom-up bitmap (top-down DIBs cannot be compressed).
It can be one of the following values:
Value Description
BI_RGB An uncompressed format.

BI_RLE8 A run-length encoded (RLE)
format for bitmaps with 8 bits
per pixel. The compression format
is a two-byte format consisting of
a count byte followed by a byte
containing a color index. For more
information, see the following
Remarks section.

BI_RLE4 An RLE format for bitmaps with 4
bits per pixel. The compression
format is a two-byte format
consisting of a count byte followed
by two word-length color indices.
For more information, see the
following Remarks section.

BI_BITFIELDS Specifies that the bitmap is not
compressed and that the color table
consists of three doubleword color
masks that specify the red, green,
and blue components, respectively,
of each pixel. This is valid when
used with 16- and 32-bits-per-pixel
bitmaps.

biSizeImage
Specifies the size, in bytes, of the image.
This may be set to 0 for BI_RGB bitmaps.

biXPelsPerMeter
Specifies the horizontal resolution,
in pixels per meter, of the target device
for the bitmap. An application can use this
value to select a bitmap from a resource group
that best matches the characteristics of the
current device.

biYPelsPerMeter
Specifies the vertical resolution, in pixels
per meter, of the target device for the bitmap.

biClrUsed
Specifies the number of color indices in the
color table that are actually used by the
bitmap. If this value is zero, the bitmap uses
the maximum number of colors corresponding to
the value of the biBitCount member for the
compression mode specified by biCompression.

If biClrUsed is nonzero and the biBitCount member
is less than 16, the biClrUsed member specifies
the actual number of colors the graphics engine
or device driver accesses. If biBitCount is 16 or
greater, then biClrUsed member specifies the size
of the color table used to optimize performance of
Windows color palettes. If biBitCount equals 16 or
32, the optimal color palette starts immediately
following the three doubleword masks.

If the bitmap is a packed bitmap (a bitmap in
which the bitmap array immediately follows the
BITMAPINFO header and which is referenced by a
single pointer), the biClrUsed member must be
either 0 or the actual size of the color table.

biClrImportant
Specifies the number of color indices that
are considered important for displaying the bitmap.
If this value is zero, all colors are important.

够复杂吧 加油喔 后天要面试了 没时间帮你翻成中文
不过应该看的懂吧

Follow Ups: