Can you create a 1Bpp png

  • Thread starter Thread starter James Dean
  • Start date Start date
J

James Dean

I have read that you can create a 1bpp png image but has anyone any idea
how to do it?......
 
Hi James,

Don't you post this question two times before?

Nicholas Paldino answer to it tomorrow.

I can only give you a sample:

// 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!");
}
}

Regards

Marcin
 
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?......
 
Hi James,

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).
 
Back
Top