我读了这个链接Converting 8 bit color into RGB value
然后我尝试了如下的 VB.NET 代码:
Private Sub picturebox1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles picturebox1.MouseDown
Dim bm As New Bitmap(picturebox1.Image)
Dim Red As Byte = bm.GetPixel(e.X, e.Y).R
Dim Green As Byte = bm.GetPixel(e.X, e.Y).G
Dim Blue As Byte = bm.GetPixel(e.X, e.Y).B
Dim ColorNumber As Byte = ((Red / 32) << 5) + ((Green / 32) << 2) + (Blue / 64)
' Show Byte Number of color
MsgBox(ColorNumber)
MsgBox(Red & ":" & Green & ":" & Blue)
Red = (ColorNumber >> 5) * 32
Green = ((ColorNumber >> 2) << 3) * 32
Blue = (ColorNumber << 6) * 64
MsgBox(Red & ":" & Green & ":" & Blue)
End Sub
But when one pixel is selected, an error occurs:
算术运算导致溢出。
如何获取 256 色(8 位)图像的字节值,然后将(转换)得到的字节值恢复为 RGB 值。
谢谢 :)