vb 取某点rgb值分解后再画在另一张图上
来源:百度知道 编辑:UC知道 时间:2024/09/21 18:54:05
Option Explicit
Private Sub Command1_Click()
Picture1.AutoSize = True
Picture2.AutoSize = True
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
Private Sub Command2_Click()
Dim i, j As Integer
Dim r, g, b As Integer
Dim color As Long
For i = 0 To Picture1.Width
For j = 0 To Picture1.Height
color = Picture1.Point(i, j)
r = (color Mod 65536) Mod 256
g = (color Mod 65536) Mod 256
b = color \ 65536
Picture2.PSet (i, j), RGB(r, g, b)
Next
Next
End Sub
那么如果我设 i = 0 To Picture1.ScaleWidth 时,scalewidth和scaleheight是一个设好的定值还是会根据我取得的图的大小自动变成图的宽和高值呢?
Option Explicit
Private Sub Command1_Click()
Picture1.AutoSize = True
Picture2.AutoSize = True
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
Private Sub Command2_Click()
Dim i, j As Integer
Dim r, g, b As Integer
Dim color As Long
For i = 0 To Picture1.ScaleWidth
For j = 0 To Picture1.ScaleHeight
color = Picture1.Point(i, j)
r = (color And &HFF&)
g = (color And &HFF00&) \ 256&
b = (color And &HFF0000) \ 65536
Picture2.PSet (i, j), RGB(r, g, b)
Next j
Next i
Picture2.Refresh
End Sub
这样就可以了
你程序当中取r,g,b分量这里错了
r = (color Mod 65536) Mod 256
g = (color Mod 65536) Mod 256
b = color \ 65536
Picture2.PSet (i, j), RGB(r, g, b)