You are on page 1of 2

Computer Graphics Lab # 6

Filtering Using Set/GetPixel


In this tutorial, you build a program that demonstrates how to draw or performing filtering using the SetPixel and GetPixel commands. Here we convert half of the image to its negative values.

Design a window Form as shown above, and perform the following actions:

Design a Form with only one Button. Create the image to be changed. Visit the required pixels of the image to read its color. Reset the color into its inverse and redraw it again. Run the application and test it.

public void SetPixel ( int x, int y,

Color color )

public Color GetPixel ( int x , int y )

Dr. Mohammed Fadhl

Computer Graphic Lab

Page 1

public partial class Form1 : Form { public Form1() { InitializeComponent(); myBitmap = new Bitmap("c:\\Bicycle.jpg"); } Bitmap myBitmap ; protected override void OnPaint(PaintEventArgs e) { // Draw myBitmap to the screen. e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, myBitmap.Height); } private void button1_Click(object sender, EventArgs e) { for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++) { for (int Ycount = 0; Ycount < myBitmap.Height/2; Ycount++) { // Negative image Color pixel = myBitmap.GetPixel(Xcount, Ycount); pixel = Color.FromArgb(255 - pixel.R, 255 - pixel.G, 255 - pixel.B); myBitmap.SetPixel(Xcount, Ycount, pixel); } }
Invalidate(); } }

ASSIGNMENT : Do the negative image for left half of the image. Calculate the number of pixel with Red color greater than 100. Draw a Line on the image using the SetPixel and getpixel.
Computer Graphic Lab Page 2

Dr. Mohammed Fadhl

You might also like