We want to convert Tiff byte array to Png byte array using Aspose components.
Can you please share the code samples with different customization options for compression, color depth etc.
We need to maintain the original quality with reduced file size
in order to convert TIFF byte array to PNG byte array you can look through an example, which, I hope, is going to be useful:
public static byte[] TiffToPng(byte[] tiffBytes)
{
// create stream from TIFF byte array
using (var tiffStream = new MemoryStream(tiffBytes))
{
// load TIFF image
using (var tiffImage = Image.Load(tiffStream))
{
// create emtpy output stream
using (var pngStream = new MemoryStream())
{
// create and customize PNG options
var pngOptions = new PngOptions
{
// use PngColorType.TruecolorWithAlpha to get highest image color depth and keep transparency transparency of input image
ColorType = PngColorType.TruecolorWithAlpha,
// set compression level from 0 to 9 (by default it is set to 6; higher value - less size)
CompressionLevel = 9,
};
// export TIFF according to specified options
tiffImage.Save(pngStream, pngOptions);
// return PNG byte array
return pngStream.ToArray();
}
}
}
}
With your code we are converting Tiff byte array to Png byte with PngColorType=Grayscale and CompressionLevel = 9 options.
TIFF Original images size is 22.2 MB and converted PNG images size is 7.95 MB. Is there any other options there to reduce more size with images retain the quality ?.
Can you please give me information below Aspose.Imaging.ImageOptions.PngOptions
Thank you for your response.
Converting Tiff byte array to Png byte with PngColorType=Grayscale and CompressionLevel = 9 options the quality is good but size is slightly high .
We want reduce more size with images retain the quality(Manageable quality) so can please suggest which following options is best and give me more information below
I would say there is no universal rule for PngFilterType pick. Each filter uses its own approach and gives different results depending on pixel data. PngFiltertype.Paeth has the most complicated implementation among the rest, although, does not always grant the least output size.
In order to get the least output image size for sure, You should pick PngFiltertype.Adaptive, but it takes more time for calculations. Progressive option may also reduce output size combined with filter usage.
Try to run conversion with different PngOptions, so you will clearly see the output size difference.