1,486
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form_Load()
Me.AutoDraw=False
Me.ScaleMode = vbPixels
End Sub
Private Sub Form_Paint()
Me.Line (10, 10)-(Me.ScaleWidth - 10, Me.ScaleHeight - 10), , B
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
Me.Line (10, 10)-(Me.ScaleWidth - 10, Me.ScaleHeight - 10), , B
End Sub
Option Explicit
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Const Bits As Long = 32 '颜色深度,这里把所有图像都按照32位来处理
Private bi24BitInfo As BITMAPINFO '定义BMP信息
Private Const BI_RGB = 0&
Private Type BITMAPINFOHEADER '40 bytes
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
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private ColVal() As Byte '用于存放从DIB输入的像素值
Private Sub Command1_Click()
Dim MemDC As Long
MemDC = CreateCompatibleDC(Form2.hdc)
SelectObject MemDC, Form2.Picture.Handle
'BitBlt Me.hdc, 0, 0, 200, 200, MemDC, 0, 0, vbSrcCopy
'将字转换为二进制数组
DibGet MemDC, 1, 1, 200, 200
Dim R As Integer
Dim G As Integer
Dim B As Integer
''''''''''''''''''''''''''''''''''''''''''''''''''
'逐点回显整幅图像
Dim i As Long
Dim j As Long
For i = 0 To 199
For j = 0 To 199
R = ColVal(2, i, 199 - j)
G = ColVal(1, i, 199 - j)
B = ColVal(0, i, 199 - j)
SetPixel Me.hdc, i, j, RGB(R, G, B)
Next j
Next i
''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
'将DC转换成二进制数据
Private Sub DibGet(ByVal IdSource As Long, XBegin As Long, ByVal YBegin As Long, ByVal XEnd As Long, ByVal YEnd As Long)
Dim iBitmap As Long
Dim iDC As Long
Dim i As Long
Dim w As Long
Dim h As Long
Dim InPutWid As Long
Dim InPutHei As Long
InPutWid = XEnd - XBegin
InPutHei = YEnd - YBegin
w = InPutWid + 1
h = InPutHei + 1
i = (Bits \ 8) - 1
ReDim ColVal(i, InPutWid, InPutHei)
With bi24BitInfo.bmiHeader
.biBitCount = Bits
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = w
.biHeight = h
End With
iBitmap = GetCurrentObject(IdSource, 7&)
GetDIBits IdSource, iBitmap, 0&, h, ColVal(0, 0, 0), bi24BitInfo, 0&
DeleteObject iBitmap
End Sub
Private Sub Form_Load()
Form2.Show
End Sub
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 3000
Timer1.Enabled = True
Me.WindowState = 1
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Set Me.Picture = LoadPicture("e:\pic\1.jpg") '这里请自行替换成本机上任意一张图片,必须大于200×200像素
Me.Caption = "图像加载完毕,可以开始获取"
End Sub