JPG is one of the most popular and widely used image formats. However, JPG images lose quality each time they are saved. Therefore, you may need to convert them into a lossless format such as PNG. To perform this conversion programmatically from within the .NET applications, this article shows how to convert a JPG image to PNG in C#.
C# .NET API for JPG to PNG Conversion
Aspose.Imaging for .NET is a feature-rich image processing API to manipulate a multitude of image formats. Moreover, it provides a powerful converter that lets you convert images from one format to another with high fidelity. In this article, we will use this API to convert our JPG images to PNG format. You can either download the API’s DLL or install it directly from NuGet.
PM> Install-Package Aspose.Imaging
Convert a JPG Image to PNG in C#
It is quite straightforward to convert a JPG image to PNG format using Aspose.Imaging for .NET. You only need to load the JPG file and save it as a PNG image. The following are the steps to convert a JPG image to PNG in C#.
- Load the JPG file using Image class.
- Create an instance of PngOptions class.
- Set PngOptions.ColorType property to FileFormats.Png.PngColorType.TruecolorWithAlpha.
- Convert JPG image to PNG using Image.Save(string, PngOptions) method.
The following code sample shows how to convert a JPG image to PNG format in .NET applications.
Get a Free API License
You can get a free temporary license to use Aspose.Imaging for .NET without evaluation limitations.
JPG to PNG conversion is often performed to convert images to a lossless format. In this article, you have learned how to convert JPG images to PNG format programmatically in C#. Thus, you can easily embed JPG to PNG conversion into your .NET applications. In addition, you can explore more about the .NET image processing API using documentation. Also, you can post your queries on our forum.