主题:图片处理
海军527
[专家分:40] 发布于 2010-12-27 19:19:00
请大家帮帮我,如何直接获得捕捉图片的大小和二进制的数据,而不是用Savepicture保存文件在获取?
回复列表 (共1个回复)
沙发
一江秋水 [专家分:9680] 发布于 2010-12-30 16:29:00
如果你的图片在剪贴板中,可以这样:
Option Explicit
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
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 RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
'rgbReserved As Byte
End Type
Private Type BITMAPINFO '定义BMP信息头
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Type RGB
B As Byte
G As Byte
R As Byte
A As Byte
End Type
Private Sub Command1_Click()
Dim Buffer() As RGB '缓冲区
Dim W As Long, H As Long '图像宽,高
Dim bi24BitInfo As BITMAPINFO
Dim p As IPictureDisp
Set p = Clipboard.GetData '获得剪贴版中图片
W = CLng(p.Width / 26.46) '转成像素单位
H = CLng(p.Height / 26.46)
ReDim Buffer(1 To W, 1 To H)
With bi24BitInfo.bmiHeader
.biBitCount = 32 '颜色深度32位真彩
.biCompression = 0
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = W
.biHeight = H
End With
GetDIBits GetDC(Me.hwnd), p.Handle, 0, H, Buffer(1, 1), bi24BitInfo, 0
Debug.Print W, H, UBound(Buffer), UBound(Buffer, 2)
End Sub
我来回复