Hello,
Just opening and saving any JPG image with Aspose is producing an output file which is half the file size of Original. More importantly, output file is of quite low quality. Then, we used another approach of saving the file using JpgCreateOptions. However, we noticed that output file was again of low quality.
Code snippet is share below for both the approaches. Also, attaching a zip file with input and output files for your reference.
We would like to produce an output file of similar size and quality using Aspose. Could you please look into this and share your findings?
public static void RunApproach1()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JPEG();
// Load an image using the factory method Load exposed by Image class
using (Image image = Image.Load(dataDir + "aspose-logo.jpg"))
{
image.Save(dataDir + "aspose-logo_out.jpg");
}
}
// Output is:
// aspose-logo.jpg: Original size is 14.8 kb. After saving, 7.95 kb.
// Image2.jpg: Original size is 256 kb. After saving, 130 kb.
public static void RunApproach2()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_JPEG();
string sourceFile = dataDir + @"aspose-logo.jpg";
string destFileName = dataDir + @"aspose-logo_Output.jpg";
using (var newImage = (RasterImage)Image.Load(sourceFile))
{
//Create an instance of JpegOptions for resultant Jpeg file
var JpgCreateOptions = new ImageOptions.JpegOptions();
//Set the Quality
JpgCreateOptions.Quality = 100;
JpgCreateOptions.CompressionType = JpegCompressionMode.Progressive;
//Set the file source of resultant Jpeg. Last parameter denotes isTemporal
JpgCreateOptions.Source = new Sources.FileCreateSource(destFileName, false);
//Create a new JpegImage using JpegOptions and size in Width and Height of source image
using (var JpgImage = (JpegImage)Image.Create(JpgCreateOptions, newImage.Width, newImage.Height))
{
//Set Resolution
//JpgImage.HorizontalResolution = 300;
//JpgImage.VerticalResolution = 300;
if (JpgImage.ExifData == null)
{
JpgImage.ExifData = new JpegExifData();
}
JpgImage.ExifData.ResolutionUnit = Exif.Enums.ExifUnit.Inch;
JpgImage.ExifData.XResolution = new FileFormats.Tiff.TiffRational((uint)newImage.Width);
JpgImage.ExifData.YResolution = new FileFormats.Tiff.TiffRational((uint)newImage.Height);
//Load all Pixels (Bitmap information) of source image and save them on Jpeg
JpgImage.SavePixels(JpgImage.Bounds, newImage.LoadPixels(newImage.Bounds));
//JpgImage.Resize(width, height, ResizeType.LanczosResample);
//Save the Jpeg
JpgImage.Save();
}
}
}
// Output is:
// aspose-logo.jpg: Original size is 14.8 kb. After saving, 11.5 kb.
// Image2.jpg: Original size is 256 kb. After saving, 873 kb.
InputAndOutputFiles.zip (1.3 MB)