如何用API以最快速度把数组里的RGB颜色值还原为图形并绘制到PictureBox上?最好有实例。
解决方案 »
- 大虾们请帮我改一下这段模拟鼠标单击的程序
- 网络中断怪问题,请助诊...
- 系统主界面讨论。高手请进,关于系统菜单拖放问题。100分!!!不够再加!Up有分!! 在线急等!
- 這條SQL語句如何寫
- 我在ole中Creatembed("sample.doc"),如何使用word的打印功能
- 在VB中用ADO访问Excel时报错,急!!!
- 把一个txt里的数据读出来后,删除重复出现的数据`并放到combo里去~
- 关于打印前选择打印机和纸张的问题
- 有高手用过datagrid的beforecolupdate吗?解决问题就一定给分(一直在线)
- 如何知道用户选择了取消按钮?
- 如何将根据RGB颜色计算出色调\饱和度\亮度?
- 把一个String 拆成两行,结果vb死了
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim PicInfo As BITMAP
Private idata() As BytePrivate Sub Command1_Click()
Dim Elapse As Long '记录所用时间
GetObject Picture1.Image, Len(PicInfo), PicInfo
ReDim idata(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte
Randomize
For i = 1 To PicInfo.bmWidth * PicInfo.bmHeight * 3
idata(i) = CInt(Rnd * 255) '生成随机图象数据
Next
Elapse = GetTickCount
SetBitmapBits Picture1.Image, UBound(idata), idata(1) '显示
Picture1.Refresh
MsgBox "用时" & GetTickCount - Elapse & "毫秒"
End Sub
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 CreateCompatibleDC Lib "gdi32" (ByVal HDC As Long) As Long
Private Declare Function DeleteDC 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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function SetDIBits Lib "gdi32" (ByVal HDC 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 GetTickCount Lib "kernel32" () As Long
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0&
Private Const LR_LOADFROMFILE = &H10
Private Const IMAGE_BITMAP = 0&Private idata() As Byte 'holds bitmap data
Private PicInfo As BITMAP 'bitmap info structurePrivate Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End TypePrivate 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 TypePrivate Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End TypePrivate Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Public Sub ShowPic(ByVal pic As Long, data() As Byte) '显示位图
Dim hdcNew As Long
Dim oldhand As Long
Dim ret As Long
Dim BytesPerScanLine As Long '一个扫描行的长度
Dim PadBytesPerScanLine As Long
Dim DIBInfo As BITMAPINFO 'Device Ind. Bitmap info structure
Call GetObject(pic, Len(PicInfo), PicInfo) '取得对指定对象进行说明的一个结构,hobject为位图,刷子等的句柄, 'count欲取回的字节数。通常是由lpObject定义的那个结构的长度
hdcNew = CreateCompatibleDC(0&) '创建一个与屏幕兼容的设备场景
oldhand = SelectObject(hdcNew, pic)
With DIBInfo.bmiHeader
.biSize = 40 'bmp3.0
.biWidth = PicInfo.bmWidth
.biHeight = -PicInfo.bmHeight '从下往上扫描
.biPlanes = 1
.biBitCount = 24 '24位位图,默认情况下Windows不会处理最高8位,可以将它作为自己的Alpha通道
.biCompression = BI_RGB '无压缩
.biSizeImage = .biWidth * .biHeight * 3 '图像大小
End With
ret = SetDIBits(hdcNew, pic, 0, PicInfo.bmHeight, data(1, 1, 1), DIBInfo, DIB_RGB_COLORS)
SelectObject hdcNew, oldhand
DeleteDC hdcNew
End Sub
Private Sub Command1_Click()
Dim Elapse As LongCall GetObject(Picture1.Image, Len(PicInfo), PicInfo) '取得对指定对象进行说明的一个结构,hobject为位图,刷子等的句柄, 'count欲取回的字节数。通常是由lpObject定义的那个结构的长度
ReDim idata(1 To PicInfo.bmWidth, 1 To PicInfo.bmHeight, 1 To 3) As Byte
Randomize
For i = 1 To PicInfo.bmWidth
For j = 1 To PicInfo.bmHeight
For k = 1 To 3
idata(i, j, k) = CInt(Rnd * 255) ''生成随机图象数据,此处用一三维数组,分别保存RGB值
Next
Next
NextElapse = GetTickCount
Call ShowPic(Picture1.Image, idata)
Picture1.Refresh
MsgBox "用时" & GetTickCount - Elapse & "毫秒"
End Sub