VB声明
Declare Function SetPixelV Lib "gdi32" Alias "SetPixelV" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
说明
在指定的设备场景中设置一个像素的RGB值
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hdc Long,一个设备场景的句柄
x,y Long,要设置的点,用逻辑坐标表示
crColor Long,指定像素的新RGB颜色值
注解
这个函数比SetPixel快一些,但不会返回设置的实际颜色。可用GetDeviceCaps判断设备是否支持这个函数
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y 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 Sub Command1_Click()
Dim i As Long, j As Long
Dim color As Long
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
For i = 1 To Picture2.ScaleHeight
For j = 1 To Picture2.ScaleWidth
color = GetPixel(Picture2.hdc, j, i)
If color <> 0 Then SetPixel Picture1.hdc, j, i, color
Next j
Next i
End Sub