0% found this document useful (0 votes)
17 views7 pages

Image File Dialogs in C# Code

The document describes code for an image processing application. It includes code to open an image file, extract RGB pixel data, perform brightness enhancement and noise reduction functions, and save the processed image. Functions include opening and saving file dialogs, locking bitmap data, and applying average pixel filters within a class.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Image File Dialogs in C# Code

The document describes code for an image processing application. It includes code to open an image file, extract RGB pixel data, perform brightness enhancement and noise reduction functions, and save the processed image. Functions include opening and saving file dialogs, locking bitmap data, and applying average pixel filters within a class.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Code 1 OpenFileDialog openFileDialog = new OpenFileDialog(); [Link] = " " ; [Link] = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.

jpg| All valid files (*.bmp/*.jpg)|*.bmp/*.jpg"; [Link] = 1 ; [Link] = true; if([Link] == [Link]()) { [Link] = true; [Link] = new Bitmap([Link]); [Link](); Bitmap b = new Bitmap((Bitmap) [Link]); BitmapData bmData = [Link](new Rectangle(0, 0, [Link], [Link]), [Link], PixelFormat. Format24b ppRgb); int stride = [Link]; [Link] Scan0 = bmData.Scan0; unsafe { byte * p = (byte *)(void *)Scan0; int nOffset = stride - [Link]*3; r_data = new byte[[Link],[Link]]; g_data = new byte[[Link],[Link]]; b_data = new byte[[Link],[Link]]; for(int y=0;y<[Link];++y) { for(int x=0;x<[Link];++x) { b_data[x,y] = p[0]; g_data[x,y] = p[1]; r_data[x,y] = p[2]; p +=3; } p += nOffset;

} } } [Link] = "File " + [Link] + " dibuka.\n ";

Code 2 Bitmap copy = new Bitmap((Bitmap) this. [Link]); SaveFileDialog saveFileDialog = new SaveFileDialog(); [Link] = " " ; [Link] = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*bmp/*.jpg)|*.bmp/*.jpg" ; [Link] = 1 ; [Link] = true ; if([Link] == saveFileDialog. ShowDialog()) { [Link]([Link]); } [Link] = "File hasil proses disimpan.";

Code 4 /* * Created by SharpDevelop. * User: Danny * Date: 4/30/2013 * Time: 8:52 PM * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using [Link]; using [Link]; using [Link]; // ditambahkan manual using [Link];

namespace Program_Pengolah_Citra { /// <summary> /// Description of MainForm. /// </summary> public partial class MainForm : Form { byte [,] r_data; byte [,] g_data; byte [,] b_data; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } public class ImageOperator { public static bool Perbaikan(Bitmap b, int signal) { BitmapData bmData = [Link](new Rectangle(0, 0, [Link],[Link]), [Link], PixelFormat. Format24b ppRgb); int stride = [Link]; [Link] Scan0 = bmData.Scan0; unsafe { byte * PixelFormat =(byte *)(void *)Scan0; int nOffset = stride - [Link]*3; int red, green, blue; byte [,] r_tmp = new byte[[Link],[Link]]; byte [,] g_tmp = new byte[[Link],[Link]]; byte [,] b_tmp = new byte[[Link],[Link]]; byte [,] r_tmp2 = new byte[[Link],[Link]];

byte [,] g_tmp2 = new byte[[Link],[Link]]; byte [,] b_tmp2 = new byte[[Link],[Link]]; if(signal==1) { for(int y=0;y<[Link];++y) { for(int x=0; x < [Link];++x) { Blue =p[0]+10; if (blue<255) p[0]=(byte) blue ; else p[0]=(byte) 255; Green =p[1]+10; if (green<255) p[1]=(byte) green ; else p[1]=(byte) 255; Red =p[2]+10; if (red<255) p[2]=(byte) red ; else p[2]=(byte) 255; p +=3; } p += nOffset; } } if(signal==2) { for(int y=0;y<[Link];++y) { for(int x=0; x < [Link];++x) { b_tmp[x,y] = p[0]; g_tmp[x,y] = p[1]; r_tmp[x,y] = p[2]; p += 3; } p += nOffset; } byte * p1 = (byte *)(void *)Scan0; for(int y=1;y<[Link]- 1;++y) { for(int x=1; x < [Link]- 1;++x) { blue = (b_tmp[x,y]+b_tmp[x-1,y-1]+b_tmp[x,y-1]+b_tmp[x+1,y1]+b_tmp[x+1,y]+b_tmp[x+1,y+1]+b_tmp[x,y+1]+b_tmp[x-1,y+1]+b_tmp[x-1,y])/9; green = (g_tmp[x,y]+g_tmp[x-1,y-1]+g_tmp[x,y-1]+g_tmp[x+1,y1]+g_tmp[x+1,y]+g_tmp[x+1,y+1]+g_tmp[x,y+1]+g_tmp[x-1,y+1]+g_tmp[x-1,y])/9; red = (r_tmp[x,y]+r_tmp[x-1,y-1]+r_tmp[x,y-1]+r_tmp[x+1,y-

1]+r_tmp[x+1,y]+r_tmp[x+1,y+1]+r_tmp[x,y+1]+r_tmp[x-1,y+1]+r_tmp[x-1,y])/9; b_tmp2[x,y] = (byte) blue; g_tmp2[x,y] = (byte) green; r_tmp2[x,y] = (byte) red; p1 += 3; } p1 += nOffset; } byte * p2 = (byte *)(void *)Scan0; for(int y=0;y<[Link];++y) { for(int x=0; x < [Link];++x) { p2[0] = b_tmp2[x,y]; p2[1] = g_tmp2[x,y]; p2[2] = r_tmp2[x,y]; p2 += 3; } p2 += nOffset; } } } [Link](bmData); return true; } } } } void ThresholdingMerahToolStripMenuItemClick(object sender, EventArgs e) { } void BukaFileToolStripMenuItemClick(object sender, EventArgs e) { OpenFileDialog openFileDialog = newOpenFileDialog(); [Link] = " " ; [Link] = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg| All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";

[Link] = 1 ; [Link] = true; if([Link] == [Link]()) { [Link] = true; [Link] = newBitmap([Link]); [Link](); Bitmap b = newBitmap((Bitmap) this. [Link]); BitmapData bmData = [Link](newRectangle(0, 0, [Link], [Link]), [Link], PixelFormat. Format24b ppRgb); int stride = [Link]; [Link] Scan0 = bmData.Scan0; unsafe { byte * p = (byte *)(void *)Scan0; int nOffset = stride - [Link]*3; r_data = newbyte[[Link],[Link]]; g_data = newbyte[[Link],[Link]]; b_data = newbyte[[Link],[Link]]; for(int y=0;y<[Link];++y) { for(int x=0; x < [Link];++x) { b_data[x,y] = p[0]; g_data[x,y] = p[1]; r_data[x,y] = p[2]; p +=3; } p += nOffset; } } } [Link] = "File " + openFileDialog. FileName + " dibuka.\n "; } void SimpanFileToolStripMenuItemClick(object sender, EventArgs e)

{ Bitmap copy = new Bitmap((Bitmap) this. [Link]); SaveFileDialog saveFileDialog = new SaveFileDialog(); [Link] = " " ; [Link] = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*bmp/*.jpg)|*.bmp/*.jpg" ; [Link] = 1 ; [Link] = true ; if([Link] == saveFileDialog. ShowDialog()) { [Link]([Link]); } [Link] = "File hasil proses disimpan."; } void KeluarToolStripMenuItemClick(object sender, EventArgs e) { [Link](); } void TingkatkanKecerahanToolStripMenuItemClick(object sender, EventArgs e) { Bitmap copy = new Bitmap((Bitmap) [Link]); [Link](copy, 1); [Link] = null; [Link] = copy; [Link] = "Kecerahan ditingkatkan."; } void ReduksiNoiseToolStripMenuItemClick(object sender, EventArgs e) { Bitmap copy = new Bitmap((Bitmap) this. [Link]); [Link](copy, 2); [Link] = null; [Link] = copy; [Link] = "Noise direduksi."; } } }

You might also like