This seems to work.
Save the System.Drawing.Image to a MemoryStream.
Create a PngBitmapEncoder and set the options that you want.
Add a BitmapFrame to the PngBitmapEncoder from that memory stream.
Then save the PNG using the PngBitmapEncoder.
I hope this helps. Sorry I don't know how to control the transparency settings.
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media.Imaging;
namespace plng
{
class Program
{
static void Main(string[] args)
{
Image img = Bitmap.FromFile("foo.bmp");
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
PngBitmapEncoder enc = new PngBitmapEncoder();
enc.Interlace = PngInterlaceOption.Off;
enc.Frames.Add(BitmapFrame.Create(ms));
using (FileStream ostream = new FileStream("bar.png", FileMode.Create))
{
enc.Save(ostream);
}
}
}
}
}