0% found this document useful (0 votes)
106 views

Filtering Using Set/Getpixel: Computer Graphics Lab # 6

The document describes a tutorial on using SetPixel and GetPixel commands to perform filtering on an image. It involves designing a Windows form with a button, loading an image, getting pixel colors from half the image, inverting the colors to create a negative image, and redrawing the image. Clicking the button runs the pixel color inversion on the left half of the loaded image. The assignment asks to count pixels with red over 100 and draw a line on the image.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Filtering Using Set/Getpixel: Computer Graphics Lab # 6

The document describes a tutorial on using SetPixel and GetPixel commands to perform filtering on an image. It involves designing a Windows form with a button, loading an image, getting pixel colors from half the image, inverting the colors to create a negative image, and redrawing the image. Clicking the button runs the pixel color inversion on the left half of the loaded image. The assignment asks to count pixels with red over 100 and draw a line on the image.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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