Copied from MSDN Lib For .NetBitmap.SetPixel:设置 Bitmap 对象中指定像素的颜色。[C#] [Serializable] [ComVisible(true)] public void SetPixel( int x, int y, Color color ); 参数 x 要设置的像素的 x 坐标。 y 要设置的像素的 y 坐标。 color Color 结构,它表示要分配给指定像素的颜色。 返回值 此方法不返回值。示例 [Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作: 创建一个 Bitmap 对象。 将位图中每个像素的颜色设置为黑色。 绘制该位图。 [Visual Basic] Public Sub SetPixel_Example(e As PaintEventArgs)' Create a Bitmap object from a file.Dim myBitmap As New Bitmap("Grapes.jpg")' Draw myBitmap to the screen.e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _myBitmap.Height)' Set each pixel in myBitmap to black.Dim Xcount As IntegerFor Xcount = 0 To myBitmap.Width - 1Dim Ycount As IntegerFor Ycount = 0 To myBitmap.Height - 1myBitmap.SetPixel(Xcount, Ycount, Color.Black)Next YcountNext Xcount' Draw myBitmap to the screen again.e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _myBitmap.Height)End Sub [C#] public void SetPixel_Example(PaintEventArgs e){// Create a Bitmap object from a file.Bitmap myBitmap = new Bitmap("Grapes.jpg");// Draw myBitmap to the screen.e.Graphics.DrawImage(myBitmap,0,0,myBitmap.Width,myBitmap.Height);// Set each pixel in myBitmap to black.for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++){for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++){myBitmap.SetPixel(Xcount, Ycount, Color.Black);}}// Draw myBitmap to the screen again.e.Graphics.DrawImage(myBitmap,myBitmap.Width,0,myBitmap.Width,myBitmap.Height);}
[Serializable]
[ComVisible(true)]
public void SetPixel(
int x,
int y,
Color color
);
参数
x
要设置的像素的 x 坐标。
y
要设置的像素的 y 坐标。
color
Color 结构,它表示要分配给指定像素的颜色。
返回值
此方法不返回值。示例
[Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作: 创建一个 Bitmap 对象。
将位图中每个像素的颜色设置为黑色。
绘制该位图。
[Visual Basic]
Public Sub SetPixel_Example(e As PaintEventArgs)' Create a Bitmap object from a file.Dim myBitmap As New Bitmap("Grapes.jpg")' Draw myBitmap to the screen.e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _myBitmap.Height)' Set each pixel in myBitmap to black.Dim Xcount As IntegerFor Xcount = 0 To myBitmap.Width - 1Dim Ycount As IntegerFor Ycount = 0 To myBitmap.Height - 1myBitmap.SetPixel(Xcount, Ycount, Color.Black)Next YcountNext Xcount' Draw myBitmap to the screen again.e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _myBitmap.Height)End Sub
[C#]
public void SetPixel_Example(PaintEventArgs e){// Create a Bitmap object from a file.Bitmap myBitmap = new Bitmap("Grapes.jpg");// Draw myBitmap to the screen.e.Graphics.DrawImage(myBitmap,0,0,myBitmap.Width,myBitmap.Height);// Set each pixel in myBitmap to black.for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++){for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++){myBitmap.SetPixel(Xcount, Ycount, Color.Black);}}// Draw myBitmap to the screen again.e.Graphics.DrawImage(myBitmap,myBitmap.Width,0,myBitmap.Width,myBitmap.Height);}
我是一只小小鸟
欢迎交流!尽管问我吧,我会帮你解决的!
尽快结帖哦!我是CSDN的菜鸟,我想获得一颗星!支持我吧!
MSN&Mail: [email protected]