Praktikum 2 Konversi RGB Open and Save Image

Praktikum 2 Konversi RGB

Open and Save Image

Open Image private void open. Tool. Strip. Menu. Item_Click(object sender, Event. Args e) { Open. File. Dialog ofd = new Open. File. Dialog(); ofd. Filter = "jpg (*. jpg)|*. jpg|bmp (*. bmp)|*. bmp"; if (ofd. Show. Dialog() == Dialog. Result. OK && ofd. File. Name. Length > 0) { picture. Box 1. Size. Mode = Picture. Box. Size. Mode. Zoom; picture. Box 1. Image = Image. From. File(ofd. File. Name); } }

Save As private void save. ASTool. Strip. Menu. Item_Click(object sender, Event. Args e) { Save. File. Dialog sfd = new Save. File. Dialog(); sfd. Filter = "jpg (*. jpg)|*. jpg|bmp (*. bmp)|*. bmp"; if (sfd. Show. Dialog() == Dialog. Result. OK && sfd. File. Name. Length > 0) { picture. Box 1. Image. Save(sfd. File. Name); } }

//picture. Box 3 RGB Color Bitmap bmp 1 = new Bitmap(200, 140); Color merah = Color. From. Argb(255, 0, 0); Color putih = Color. From. Argb(255, 255); for (int y = 0; y < 70; y++) { for (int x = 0; x < 200; x++) { bmp 1. Set. Pixel(x, y, merah); } } for (int y = 70; y < 140; y++) { for (int x = 0; x < 200; x++) { bmp 1. Set. Pixel(x, y, putih); } } picture. Box 3. Image=new Bitmap(bmp 1. Height, bmp 1. Width); picture. Box 3. Image = bmp 1;

RGB Color int number 1, number 2, number 3; Int 32. Try. Parse(tb_1. Text, out number 1); for (int y = 0; y < 100; y++) out number 2); Int 32. Try. Parse(tb_2. Text, { Int 32. Try. Parse(tb_3. Text, out number 3); for (int x = 0; =x. Color. From. Argb(number 1, < 100; x++) //panel 4. Back. Color number 2, number 3); Bitmap {bit. Campur = new Bitmap(100, 100); bit. Red. Set. Pixel(x, y, red); bit. Green. Set. Pixel(x, y, green); Bitmap bit. Red = new Bitmap(100, 100); bit. Blue. Set. Pixel(x, y, blue); 100); Bitmap bit. Green = new Bitmap(100, bit. Campur. Set. Pixel(x, y, campur); Bitmap bit. Blue = new Bitmap(100, 100); } = Color. From. Argb(255, 0, 0); Color red Color }green = Color. From. Argb(0, 255, 0); Color blue = Color. From. Argb(0, 0, 255); = new Bitmap(bit. Red. Height, bit. Red. Width); Color box. Color 1. Image campur=Color. From. Argb(number 1, number 2, number 3); box. Color 1. Image = bit. Red; box. Color 2. Image = new Bitmap(bit. Green. Height, bit. Green. Width); box. Color 2. Image = bit. Green; box. Color 3. Image = new Bitmap(bit. Blue. Height, bit. Blue. Width); box. Color 3. Image = bit. Blue; box. Color 4. Image = new Bitmap(bit. Campur. Height, bit. Campur. Width); box. Color 4. Image = bit. Campur;


Bitmap bmp 3 = (Bitmap)pbox 3. Image; Color pixel. Color; pbox 6. Image = new Bitmap(pbox 6. Width, pbox 6. Height); for (int y = 0; y < bmp 3. Height; y++) { for (int x = 0; x < bmp 3. Width; x++) { pixel. Color = bmp 3. Get. Pixel(x, y); int red = pixel. Color. R; int green = pixel. Color. G; int blue = pixel. Color. B; int rata = (int)(red + green + blue) / 3; bmp 3. Set. Pixel(x, y, Color. From. Argb(rata, rata)); } } pbox 6. Size. Mode = Picture. Box. Size. Mode. Stretch. Image; pbox 6. Image = bmp 3;


Bitmap bmp 4 = (Bitmap)pbox 3. Image; Color pixel. Color; for (int y = 0; y < bmp 4. Height; y++) { for (int x = 0; x < bmp 4. Width; x++) { pixel. Color = bmp 4. Get. Pixel(x, y); int red = pixel. Color. R; int green = pixel. Color. G; int blue = pixel. Color. B; int rata = (int)(red + green + blue) / 3; if (rata < 128) { rata = 0; } else { rata = 255; } bmp 4. Set. Pixel(x, y, Color. From. Argb(rata, rata)); } } pbox 7. Size. Mode = Picture. Box. Size. Mode. Stretch. Image; pbox 7. Image = bmp 4;


//Flip Horizontal Bitmap source = (Bitmap)pbox 3. Image; Color p. C; //pixel. Color int size=source. Height; if (source. Width < source. Height) size = source. Width; Bitmap bmp 1 = new Bitmap(size, size); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { p. C = source. Get. Pixel(size-1 -x, y); bmp 1. Set. Pixel(x, y, Color. From. Argb(p. C. R, p. C. G, p. C. B)); } } pbox 4. Size. Mode = Picture. Box. Size. Mode. Stretch. Image; pbox 4. Image = bmp 1;

//Flip Vertical Bitmap bmp 2 = new Bitmap(size, size); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { int a = size - y; p. C = source. Get. Pixel(x, size-1 -y); bmp 2. Set. Pixel(x, y, Color. From. Argb(p. C. R, p. C. G, p. C. B)); } } pbox 5. Size. Mode = Picture. Box. Size. Mode. Stretch. Image; pbox 5. Image = bmp 2;


// fungsi Contrast Bitmap source = (Bitmap)pbox 3. Image; Bitmap bmp 1 = new Bitmap(source. Height, source. Width); bmp 1 = source; Color pixel. Color; int k = 30; for (int y = 0; y < source. Height; y++) { for (int x = 0; x < source. Width; x++) { pixel. Color = source. Get. Pixel(x, y); int red = pixel. Color. R; int green = pixel. Color. G; int blue = pixel. Color. B; if ((red + k) <= 255) { red = red + k; } ; if ((green + k) <= 255) { green = green + k; }; if ((blue + k) <= 255) { blue = blue + k; } ; bmp 1. Set. Pixel(x, y, Color. From. Argb(red, green, blue)); } } pbox 8. Size. Mode = Picture. Box. Size. Mode. Stretch. Image; pbox 8. Image = bmp 1;
- Slides: 15