C# Draw Rawpixels On Window Code Example


Example 1: how to draw a dot in c#


private void Form1_Paint(object sender, PaintEventArgs e)
{
using (Pen p = new Pen(Brushes.Black))
{
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
e.Graphics.DrawLine(p, 10, 10, 11, 10);
}
}

Example 2: c# windows forms draw pixel


private 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);
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable