[英]How do I create/edit a PNG file in C#?
我编写了一个可以创建数字艺术的程序。 Mandelbrot Set 和 Julia Set 等图像。 但我希望将这些图像保存为 PNG。 目前,在 Java 中,我在应用程序 window 中生成图像,然后对显示器进行屏幕截图。 但是,我失去了这些图像的更精细的细节。 此外,这种方法还可以减小图像的物理尺寸。 我希望能够用这些照片制作一张大海报。
在 C# 中,我使用以下内容: Bitmap myimage = new Bitmap("image.png");
和: myimage.SetPixel(x,y, Color.FromArgb(255*colors[x,y], 255*colors[x,y], 255*colors[x,y]);
其中colors[,]
是某个值在 0 和 1 之间。
代码运行良好,减去 Bitmap 声明。 我的理解是new Bitmap(filepath);
允许您编辑和操作 PNG 图像。 我这样想是对的吗? 如何在 C# 中创建/编辑 PNG 文件?
(编辑)PS:PNG 文件“image.png”确实存在于解决方案文件夹中。
首先,您必须了解创建 PNG 文件的分步过程。
从 BMP 创建 PNG 图像的代码
using System;
//Use following namespaces to create PNG image
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
namespace CreatePNGImage
{
class Program
{
static void Main(string[] args)
{
//Set license before creating PNG image from BMP
Aspose.Imaging.License AsposeImagingLicense = new Aspose.Imaging.License();
AsposeImagingLicense.SetLicense(@"c:\asposelicense\license.lic");
//load input BMP image
Image BmpToPngImage = Image.Load("InputBMPImage.bmp");
//set attributes of the output PNG file
PngOptions PNGImageOptions = new PngOptions();
PNGImageOptions.ResolutionSettings = new ResolutionSetting(300, 300);
PNGImageOptions.CompressionLevel = 6;
//save converted output PNG image
BmpToPngImage.Save("OutputPNGImage.png", PNGImageOptions);
}
}
}
试试这个从 c# 创建 PNG 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.