Vb.net 位图看不到图形

Vb.net 位图看不到图形,vb.net,graphics,bitmap,Vb.net,Graphics,Bitmap,我已经找了大约一个星期的答案,但我在这里的代码是徒劳的 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.W

我已经找了大约一个星期的答案,但我在这里的代码是徒劳的

    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的黑框,但它不会将像素设置为绿色

因此位图无法识别图形:

此方法将
颜色结构的
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

你想要一个绿色的矩形或者把所有的黑色像素都涂成绿色?如果bmap.GetPixel(q,w)。ToArgb=color.black.ToArgb,那么将所有的黑色像素涂成绿色…
与bmap.GetPixel(q,w)=color比较。FromArgb(&HFF000000)也可以修复。看到我的答案了吗