我正在开发一个用于转换图像的Windows应用程序,以便在android启动动画中使用。启动动画的图像应该是PNG格式,没有隔行扫描或透明度。 如何将System.Drawing.Image对象保存为PNG格式文件,无需交错或透明在VB / C#.NET ....? 我尝试过: 我读过这个...... PngBitmapEncoder类(System.Windows.Media.Imaging) [ ^ ] 但不知道如何将此类与System.Drawing.Image一起使用
I'm developing an windows application for converting images for using in android boot animation. The images for boot animation should be in PNG format and without interlace or transparency. How can i save System.Drawing.Image object as PNG formatted file without interlace or transparency in VB/C# .NET....? What I have tried: I had read this... PngBitmapEncoder Class (System.Windows.Media.Imaging)[^] But don't know how to use this class with System.Drawing.Image
推荐答案这似乎有效。 将System.Drawing.Image保存到MemoryStream。 创建一个PngBitmapEncoder并设置所需的选项。 从该内存流向PngBitmapEncoder添加一个BitmapFrame。 然后使用PngBitmapEncoder保存PNG。 我希望这会有所帮助。抱歉,我不知道如何控制透明度设置。 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); } } } } }
更多推荐
将system.drawing.image保存为PNG,无需.NET中的交错和透明
发布评论