快速得到图片框图片所有点RGB分量方法VB

来源:百度知道 编辑:UC知道 时间:2024/06/28 12:19:40
本人业余爱好人工智能,所以就学了VB因为 比较好学,但是现在有一个看来是VB不可逾越的问题难倒了我,那就是如何快速的得到图片框中图片的所有像素保存的数组里面,我在网上也差了很久,就是没有找到,如能解答不胜感谢!

例如这是我用的代码:

'-------------
Private Declare Function GetPixel Lib "gdi32" Alias_ "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As_ Long) As Long

'------------

Dim x,y as integer
Dim Pi as long
Dim Pic() as byte '保存图片各点RGB分量

redim Pic(1 to Picture.Wide,1 to Picture.Height,1 to 3) as byte

For x= 1 to Picture.Wide

For = y = 1 to Picture.Height

Pi=Getpixel(Picture.hdc,x,y)

Red = Pi& Mod 256
Green = ((pi& And &HFF00) / 256&) Mod 256&
Blue = (pi1& And &HFF0000) / 65536

Pic(x,y,1)=Red
Pic(x,y,2)=Green
Pic(x,y,3)=Blue

Next

Next

上面的方法是可以得到图片框图片每个点的像素RGB分量但是很占用CPU
还慢。

Dim B() As Byte
Dim S As String
S = App.Path & "\AA.BMP"
SavePicture Picture1.Picture, S
Open S For Binary As #1
Get #1, , B()
Close #1

Public Declare Function GetBitmapBits Lib "gdi32" Alias "GetBitmapBits" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

处理整张图片时比getPixel要快上一个数量级