图片的分辩率如何得到?

XUZIFENG 2003-08-20 06:51:42
因我要写一程序是 用扫描仪扫描图片后 原大小100%打印图片,可是程序得不到图片的
分辩率就计算不出原图片的实际尺寸,可否告诉我 BMP 和JPG 格式如何得到分辩率大小
或有无此功能得控件。
...全文
70 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-08-21
  • 打赏
  • 举报
回复
根据bmp文件格式写的,获取图片的宽度和高度:
一个picturebox,一个textbox,一个按钮:

Private Type mybmpinfo
bfType As String * 2
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
biSize As Long
biWidth As Long
biHeight As Long
End Type

Private Sub Command1_Click()
On Error Resume Next
Me.CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp|JPG files(*.jpg)|*.jpg"
Me.CommonDialog1.ShowOpen
Dim mfile As String
mfile = Me.CommonDialog1.FileName
Picture1.Picture = LoadPicture(mfile)
'用生成临时文件的办法处理jpg文件
SavePicture Picture1.Picture, App.Path + "\mytemp.bmp"
Dim mbmpinfo As mybmpinfo
Open App.Path + "\mytemp.bmp" For Binary As #1
Get #1, , mbmpinfo
Close #1
Text1.Text = "图片宽度:" + CStr(mbmpinfo.biWidth) + " 图片高度:" + CStr(mbmpinfo.biHeight)
Kill App.Path + "\mytemp.bmp"
End Sub


XUZIFENG 2003-08-21
  • 打赏
  • 举报
回复
发分了
别的是我太无用了,读不懂
rainstormmaster(rainstormmaster)的看懂了但只能读bmp的
最好有人像rainstormmaster一样写一读JPG的可加分
zyl910 2003-08-20
  • 打赏
  • 举报
回复
BMP文件格式:
http://www.fantasiasoft.net/Zyl910/VBImgOp.htm
zyl910 2003-08-20
  • 打赏
  • 举报
回复
biCompression
Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be compressed). This member 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 2-byte format consisting of a count byte followed by a byte containing a color index. For more information, see Bitmap Compression.
BI_RLE4 An RLE format for bitmaps with 4 bits per pixel. The compression format is a 2-byte format consisting of a count byte followed by two word-length color indexes. For more information, see Bitmap Compression.
BI_BITFIELDS Specifies that the bitmap is not compressed and that the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bit-per-pixel bitmaps.
BI_JPEG Windows 98, Windows NT 5.0 and later: Indicates that the image is a JPEG image.


biSizeImage
Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
Windows 98, Windows NT 5.0 and later: If biCompression is JBI_JPEG, biSizeImage indicates the size of the JPEG image buffer.

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 indexes 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, the biClrUsed member specifies the size of the color table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, the optimal color palette starts immediately following the three DWORD masks.

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

biClrImportant
Specifies the number of color indexes that are required for displaying the bitmap. If this value is zero, all colors are required.
Remarks
The BITMAPINFO structure combines the BITMAPINFOHEADER structure and a color table to provide a complete definition of the dimensions and colors of a DIB. For more information about DIBs, Device-Independent Bitmaps and BITMAPINFO.

An application should use the information stored in the biSize member to locate the color table in a BITMAPINFO structure, as follows:

pColor = ((LPSTR)pBitmapInfo +
(WORD)(pBitmapInfo->bmiHeader.biSize));

Windows 98, Windows NT 5.0 and later: The BITMAPINFOHEADER structure is extended to allow a JPEG image to be passed as the source image to StretchDIBits.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in wingdi.h.

zyl910 2003-08-20
  • 打赏
  • 举报
回复
BITMAPINFOHEADER
The BITMAPINFOHEADER structure contains information about the dimensions and color format of a device-independent bitmap (DIB).

Applications developed for Windows NT 4.0 and Windows 95 may use the BITMAPV4HEADER structure. Applications developed for Windows NT 5.0 and Windows 98 may use the BITMAPV5HEADER structure for increased functionality.

typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;

Members
biSize
Specifies the number of bytes required by the structure.
biWidth
Specifies the width of the bitmap, in pixels.
Windows 98, Windows NT 5.0 and later: If biCompression is BI_JPEG, the biWidth member specifies the width of the decompressed JPEG image file.

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.
If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.

Windows 98, Windows NT 5.0 and later: If biCompression is BI_JPEG, the biHeight member specifies the height of the decompressed JPEG image file.

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. The biBitCount member of the BITMAPINFOHEADER structure determines the number of bits that define each pixel and the maximum number of colors in the bitmap. This member must be one of the following values. Value Meaning
0 Windows 98, Windows NT 5.0 and later: The number of bits per pixel is specified or is implied by the JPEG format.
1 The bitmap is monochrome, and the bmiColors member contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, the pixel is displayed with the color of the first entry in the bmiColors table; if the bit is set, the pixel has the color of the second entry in the table.
4 The bitmap has a maximum of 16 colors, and the bmiColors member contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel contains the color in the second table entry, and the second pixel contains the color in the sixteenth table entry.
8 The bitmap has a maximum of 256 colors, and the bmiColors member contains up to 256 entries. In this case, each byte in the array represents a single pixel.
16 The bitmap has a maximum of 2^16 colors. If the biCompression member of the BITMAPINFOHEADER is BI_RGB, the bmiColors member is NULL. Each WORD in the bitmap array represents a single pixel. The relative intensities of red, green, and blue are represented with 5 bits for each color component. The value for blue is in the least significant 5 bits, followed by 5 bits each for green and red. The most significant bit is not used. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the biClrUsed member of the BITMAPINFOHEADER.
If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the bmiColors member contains three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. Each WORD in the bitmap array represents a single pixel.

Windows NT: When the biCompression member is BI_BITFIELDS, bits set in each DWORD mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not have to be used.

Windows 95 and Windows 98: When the biCompression member is BI_BITFIELDS, the system supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800.

24 The bitmap has a maximum of 2^24 colors, and the bmiColors member is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the biClrUsed member of the BITMAPINFOHEADER.
32 The bitmap has a maximum of 2^32 colors. If the biCompression member of the BITMAPINFOHEADER is BI_RGB, the bmiColors member is NULL. Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the biClrUsed member of the BITMAPINFOHEADER.
If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the bmiColors member contains three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents a single pixel.

Windows NT: When the biCompression member is BI_BITFIELDS, bits set in each DWORD mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not need to be used.

Windows 95 and Windows 98: When the biCompression member is BI_BITFIELDS, the system supports only the following 32bpp color mask: The blue mask is 0x000000FF, the green mask is 0x0000FF00, and the red mask is 0x00FF0000.



wingchi 2003-08-20
  • 打赏
  • 举报
回复
同上
James0001 2003-08-20
  • 打赏
  • 举报
回复
GetObject( IPictureDisp.Handle, LenB(BITMAP), BITMAP )
hxy2003 2003-08-20
  • 打赏
  • 举报
回复
如何得到图片的width 等数据
XUZIFENG 2003-08-20
  • 打赏
  • 举报
回复
可否写一例程给我 或详细点的说明。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧