Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Memory Strategy optimization
LoadOptions options = new LoadOptions();
options.setBufferSizeHint(50);
// Setting a memory limit of 50 megabytes for target loaded image
try (Image image = Image.load("inputFile.jpg", options))
{
JpegOptions jpegOptions = new JpegOptions();
jpegOptions.setCompressionType(JpegCompressionMode.Baseline);
jpegOptions.setQuality(100);
image.save("outputFile_Baseline.jpg", jpegOptions);
jpegOptions = new JpegOptions();
jpegOptions.setCompressionType(JpegCompressionMode.Progressive);
image.save("outputFile_Progressive.jpg", jpegOptions);
jpegOptions = new JpegOptions();
jpegOptions.setCompressionType(JpegCompressionMode.Lossless);
jpegOptions.setColorType(JpegCompressionColorMode.YCbCr);
jpegOptions.setBitsPerChannel((byte)4);
image.save("outputFile_Lossless.jpg", jpegOptions);
jpegOptions = new JpegOptions();
jpegOptions.setCompressionType(JpegCompressionMode.JpegLs);
jpegOptions.setColorType(JpegCompressionColorMode.YCbCr);
jpegOptions.setJpegLsInterleaveMode(JpegLsInterleaveMode.None);
jpegOptions.setJpegLsAllowedLossyError(3);
jpegOptions.setJpegLsPreset(null);
image.save("outputFile_JpegLs.jpg", jpegOptions);
}
// Setting a memory limit of 50 megabytes for target created image
try (JpegOptions createOptions = new JpegOptions())
{
createOptions.setCompressionType(JpegCompressionMode.Progressive);
createOptions.setBufferSizeHint(50);
createOptions.setSource(new FileCreateSource("createdFile.jpg", false));
try (Image image = Image.create(createOptions, 1000, 1000))
{
image.save(); // save to same location
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.