Filtering Using Set/Getpixel: Computer Graphics Lab # 6
Filtering Using Set/Getpixel: Computer Graphics Lab # 6
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.
Color color )
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