将system.drawing.image保存为PNG,无需.NET中的交错和透明

编程入门 行业动态 更新时间:2024-10-25 19:20:10
本文介绍了将system.drawing.image保存为PNG,无需.NET中的交错和透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个用于转换图像的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中的交错和透明

本文发布于:2023-07-27 00:22:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:保存为   透明   drawing   system   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!