I am not sure in what step your problem is, so first I will explain how to create/edit a four band bitmap and then how to save it as a .png.
To add an alpha channel to an image, you need to set up your bitmap a bit differently:
int height = b.Height;
int width = b.Width;
BitmapData bmData = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - width * 4;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
// do whatever pixel change you want
p += 4;
p += nOffset;
Notice the pixel format is now set up as Format32bppArgb, instead of the typical 24bpp. Alos be careful and remeber you need to increment the pixel value by four instead of three, and likewise nOffset is multiplied by four instead of three.
Once you have your bitmap created, it can then be saved as a .png via the bitmap.save command as follows.
b.Save(tbDestination.Text, ImageFormat.Png); //save the bitmap as a .PNG file to the supplied destination
modified on Tuesday, April 29, 2008 7:31 AM
Last Visit: 31-Dec-99 18:00 Last Update: 29-Oct-14 22:15