Point的方式太慢了,有没有其他办法能快速的保存呢?
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long Private Sub Command1_Click() Dim lpBits() As Byte Dim hBitmap, dwCount As Long, i As Long Dim nWidth As Long, nHeight As Long '以下代码取图像的像素数组,每3个字节表示一个像素 hBitmap = Me.Picture1.Picture.Handle dwCount = GetBitmapBits(hBitmap, 0, ByVal 0&) ReDim lpBits(dwCount - 1) GetBitmapBits hBitmap, dwCount, lpBits(0) '以下代码把图像中的第二行的前50个像素的颜色设为红色 nWidth = Me.ScaleX(Me.Picture1.Picture.Width, vbHimetric, vbPixels) For i = nWidth * 3 - 1 To nWidth * 3 + 50 Step 3 lpBits(i) = 255 lpBits(i + 1) = 0 lpBits(i + 2) = 0 Next SetBitmapBits hBitmap, dwCount, lpBits(0) Me.Picture1.Refresh End Sub
jpg等picture能显示的图我一般用picture控件读入 再GetBitmapBits
png比较麻烦了,要么加转换的类 要么通过webbrowser显示出来copy到picture控件里
其实你用GetBitmapBits 得到的b()就已经是图像点阵的雏形了 只不过需要进行一下RGB转换
不过由b()得到的新RGB数组的第一个像素点是左上角开始的