// Windows Application - project
// 2 x Button
// 1 x PictureBox (anchor it L-T-R-B for resizing)
// 1 x SaveFileDialog
// add these methods as a buttons Click handlers!
private void button1_Click(object sender, System.EventArgs e) {
// here bmp with 1bpp is created
Bitmap bmp=new Bitmap(pictureBox1.ClientSize.Width
, pictureBox1.ClientSize.Height
, System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
if( pictureBox1.Image!=null ) {
Image img=pictureBox1.Image;
pictureBox1.Image=null;
img.Dispose();
}
pictureBox1.Image=bmp;
}
private void button2_Click(object sender, System.EventArgs e) {
Image img=pictureBox1.Image;
if( img!=null ) {
saveFileDialog1.DefaultExt="png";
if( saveFileDialog1.ShowDialog(this)==DialogResult.OK ) {
try {
// here this bmp is saved as a PNG 1bpp image
img.Save(saveFileDialog1.FileName
, System.Drawing.Imaging.ImageFormat.Png);
}
catch(Exception ex) {
MessageBox.Show("Save error: "+ex.Message);
}
}
}
else {
MessageBox.Show("There's no image to save!");
}
}
Are u sure that does not save the file as an 8bpp png and doesn't save
it properly either. I saved my 1bpp image as a png just like you did
here......but it did not save it correctly. Maybe the way u are using
the picturebox is how u are doing it.....is it?....how come when i have
my 1bpp bitmap say called OneBppBitmap...then i do:
OneBppBitmap.save("filename.png",ImageFormat.Png)......it doesn't do it
right?......
My image browser (InfranView) displays the saved PNG file info as a:
width x height x 1bpp, but Window explorer informs about 8bpp.
But i'm not sure about details of PNG format, so it can depend
on entries in 8bpp palette.
I'm pretty sure that my pictureBox has nothig to do with a PNG
saving.
Regards
Marcin
PS: Maybe PNG supports only 8bpp & 24bpp (in standard or in .NET
libraries).
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.