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

Bitmap

The document describes opening an image file, accessing its pixel data, and storing the red, green, and blue channels of the pixel data in separate arrays. It uses an open file dialog to select an image file, loads the file, locks the pixel bits, and then iterates through the pixels storing each color channel value in a separate array.

Uploaded by

rnurmawati
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Bitmap

The document describes opening an image file, accessing its pixel data, and storing the red, green, and blue channels of the pixel data in separate arrays. It uses an open file dialog to select an image file, loads the file, locks the pixel bits, and then iterates through the pixels storing each color channel value in a separate array.

Uploaded by

rnurmawati
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bitmap copy = new Bitmap((Bitmap)this.procImage.

Image);
SaveFileDialog saveFileDialog = new SaveFileDialog();

saveFileDialog.InitialDirectory = " ";


saveFileDialog.Filter = "Bitmap files(*.bmp)|*.bmp|Jpeg
files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg" ;
saveFileDialog.FilterIndex = 1 ;
saveFileDialog.RestoreDirectory = true;

if(DialogResult.OK == saveFileDialog.ShowDialog())
{
copy.Save(saveFileDialog.FileName);
}
textBox1.Text = "File hasil proses disimpan.";

OpenFileDialog openFileDialog = new OpenFileDialog();

openFileDialog.InitialDirectory = " " ;


openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg
files (*.jpg)|*.jpg| All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";
openFileDialog.FilterIndex = 1 ;
openFileDialog.RestoreDirectory = true ;

if(DialogResult.OK == openFileDialog.ShowDialog() )
{
this.AutoScroll = true;
this.origImage.Image = new
Bitmap(openFileDialog.FileName);
this.Invalidate();

Bitmap b = new Bitmap((Bitmap) this.origImage.Image);


BitmapData bmData = b.LockBits(new Rectangle(0, 0,
b.Width, b.Height),ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

int stride = bmData.Stride;


System.IntPtr Scan0 = bmData.Scan0;

unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
r_data = new byte[b.Width,b.Height];
g_data = new byte[b.Width,b.Height];
b_data = new byte[b.Width,b.Height];

for(int y=0;y<b.Height;++y)
{
for(int x=0;x<b.Width;++x)
{
b_data[x,y] = p[0];
g_data[x,y] = p[1];
r_data[x,y] = p[2];
p += 3;
}
p += nOffset;
}
}

}
textBox1.Text = "File " + openFileDialog.FileName + "
dibuka.\n ";

You might also like