Set or Save Transparent Image in C#
Contents
[
Hide
]
Save transparent image with transparency
Issue : Image transparency loss.
Tips : It is necessary to use ColorMode TrueColorWithAlpha to save png with transparency.
Example of conversion transparent png to transparent png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.ImageOptions; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads"; | |
var inputFile = Path.Combine(templatesFolder, $"template.png"); | |
var outputFile = Path.Combine(templatesFolder, $"output.png"); | |
using (var image = (RasterImage)Aspose.Imaging.Image.Load(inputFile)) | |
{ | |
image.Save( | |
outputFile, | |
new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
File.Delete(outputFile); |
Example of conversion transparent tiff to transparent png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.ImageOptions; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads"; | |
var inputFile = Path.Combine(templatesFolder, $"template.tiff"); | |
var outputFile = Path.Combine(templatesFolder, $"output.png"); | |
using (var image = (RasterImage)Aspose.Imaging.Image.Load(inputFile)) | |
{ | |
image.Save( | |
outputFile, | |
new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
File.Delete(outputFile); |
Example of conversion transparent gif to transparent png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.ImageOptions; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads"; | |
var inputFile = Path.Combine(templatesFolder, $"template.gif"); | |
var outputFile = Path.Combine(templatesFolder, $"output.png"); | |
using (var image = (RasterImage)Aspose.Imaging.Image.Load(inputFile)) | |
{ | |
image.Save( | |
outputFile, | |
new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
File.Delete(outputFile); |
Example of conversion transparent webp to transparent png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.ImageOptions; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads"; | |
var inputFile = Path.Combine(templatesFolder, $"template.webp"); | |
var outputFile = Path.Combine(templatesFolder, $"output.png"); | |
using (var image = (RasterImage)Aspose.Imaging.Image.Load(inputFile)) | |
{ | |
image.Save( | |
outputFile, | |
new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
File.Delete(outputFile); |