我一直在寻找一个星期的答案,但一切都是徒劳的我在这里有代码
Dim bmap As Bitmap
bmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim g As Graphics = graphics.FromImage(bmap)
g.FillRectangle(Brushes.Black, 0, 0, 100, 100)
For q As Integer = 0 To bmap.Width - 1
For w As Integer = 0 To bmap.Height - 1
If bmap.GetPixel(q, w) = Color.Black Then
bmap.SetPixel(q, w, Color.Green)
End If
Next
Next
PictureBox1.Image = bmap
因此,当我点击按钮时,它将绘制100 x 100黑色框,但不会将像素设置为绿色
因此位图无法识别图形
答案 0 :(得分:1)
From msdn about Color
equality operator:
此方法比较{strong> ARGB
结构的Color
值。
它还会对某些状态标志进行比较。 如果你想要
比较两个 ARGB
结构的 Color
值,比较它们
使用 ToArgb 方法。
所以要比较必须使用 ToArgb 方法
If bmap.GetPixel(q, w).ToArgb = Color.Black.ToArgb Then
来自源代码的一些内部。
我们看到了
对于Color.Black
KnownColor
,这个ctor将被称为
internal Color(KnownColor knownColor) {
value = 0;
state = StateKnownColorValid;
name = null;
this.knownColor = (short)knownColor;
}
但是GetPixel
Color.FromArgb(value)
被称为
private Color(long value, short state, string name, KnownColor knownColor) {
this.value = value;
this.state = state;
this.name = name;
this.knownColor = (short)knownColor;
}
public static Color FromArgb(int argb) {
return new Color((long)argb & 0xffffffff, StateARGBValueValid, null, (KnownColor)0);
}
因此,您的案例的另一个修复可能是
If bmap.GetPixel(q, w) = Color.FromArgb(&HFF000000) Then