Académique Documents
Professionnel Documents
Culture Documents
Design a window Form as shown above, and perform the following actions:
Design a form with two Picturebox tools and one button and load an image into the left picture box. Using the suitable values to fill the ColorMatrix. . Creates and sets the attributes of the adjusted image within the memory. Draws the adjusted image to the right picture box. ColorMatrix colorMatrix = new ColorMatrix(newfloat[ ][ ] { newfloat[] {-1, -1, -1, 0, 0}, newfloat[] { -1, -1, -1, 0, 0}, newfloat[] { -1, -1, -1, 0, 0}, newfloat[] {0, 0, 0, 1, 0}, newfloat[] {1, 1, 1, 1, 1} };
The color matrix is applied to every pixel in the image as it is drawn into the graphics buffer. The following figure shows how a single source pixel is converted to a single destination pixel.
Dr. Mohammed Fadhl Computer Graphic Lab Page 1
Source
* Rr Rg
Matrix Gr Gg Gb Ga Go Br Bg Bb Ba Bo
= Ar Ag Ab Aa Ao 0 0
Destination
Rs
Gs
Bs
As
* R b
0 = Rd 0 0
Gd
Bd
Ad
Ra Ro
Rd = (Rr * Rs) + (Rg + Gs) + (Rb * Bs) + (Ra * As) + Ro Gd = (Gr * Rs) + (Gg + Gs) + (Gb * Bs) + (Ga * As) + Go Bd = (Br * Rs) + (Bg + Gs) + (Bb * Bs) + (Ba * As) + Bo Ad = (Ar * Rs) + (Ag + Gs) + (Ab * Bs) + (Aa * As) + Ao Complete the code: // 1# DO Create image. private void button1_Click(object sender, EventArgs e) { // 2# DO Draw the image in picturebox1 // 3# DO suitable values to fill the ColorMatrix image. float[][] dataArray ; // . . . . . . // 4# DONE
// 5# DONE Take space in memory to set the attribute of adjusted image Graphics g = Graphics.FromImage(image1); Rectangle rect = new Rectangle(0, 0, image1.Width, image1.Height); g.DrawImage(image1, rect, 0, 0, image1.Width, image1.Height, GraphicsUnit.Pixel, imageAttributes); this.Invalidate(); } } private void Form1_Paint(object sender, PaintEventArgs e) { // 6# Draws the adjusted image to the right picturebox. } Assignment: Do the negative image with setpixel/getpixel. Save the inverted image. Invert only the second half of the image (or the right half of it).
Dr. Mohammed Fadhl Computer Graphic Lab Page 2