Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 25, 2021 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/17961f60f01297fe54c8e815099c7c85 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/17961f60f01297fe54c8e815099c7c85 to your computer and use it in GitHub Desktop.
Convert GIF to PNG BMP JPEG TIFF in Java
// Load GIF image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.gif");
// Set image options
com.aspose.imaging.imageoptions.BmpOptions options = new com.aspose.imaging.imageoptions.BmpOptions();
// Convert first frame of GIF to BMP
options.setMultiPageOptions(new com.aspose.imaging.imageoptions.MultiPageOptions(1));
// Save BMP image
image.save("gif-to-bmp.bmp", options);
// Load GIF image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.gif");
// Set image options
com.aspose.imaging.imageoptions.JpegOptions options = new com.aspose.imaging.imageoptions.JpegOptions();
// Specify the frame to be converted
com.aspose.imaging.imageoptions.MultiPageOptions multiPageOptions = new com.aspose.imaging.imageoptions.MultiPageOptions(
new com.aspose.imaging.IntRange(2, 2));
// Convert frame of GIF to JPG
options.setMultiPageOptions(multiPageOptions);
// Save JPG image
image.save("gif-to-jpg.jpg", options);
// Load GIF image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.gif");
// Set image options
com.aspose.imaging.imageoptions.PngOptions options = new com.aspose.imaging.imageoptions.PngOptions();
// Specify the frame to be converted
com.aspose.imaging.imageoptions.MultiPageOptions multiPageOptions = new com.aspose.imaging.imageoptions.MultiPageOptions(
new com.aspose.imaging.IntRange(2, 2));
// Convert frame of GIF to JPG
options.setMultiPageOptions(multiPageOptions);
// Save PNG image
image.save("gif-to-png.png", options);
// Input file's name
String fileName = "Animation.gif";
// Output files
String outputFilePath = "_FullFrame.tif";
String outputFilePath1 = "_NonFullFrame.tif";
// Load GIF image
try (com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName))
{
// Set multipage options
com.aspose.imaging.imageoptions.MultiPageOptions multiPageOptions = new com.aspose.imaging.imageoptions.MultiPageOptions(new com.aspose.imaging.IntRange(2, 5));
com.aspose.imaging.imageoptions.TiffOptions tiffOptions = new com.aspose.imaging.imageoptions.TiffOptions(TiffExpectedFormat.TiffDeflateRgb);
tiffOptions.setMultiPageOptions(multiPageOptions);
// Set frame size
tiffOptions.setFullFrame(true);
image.save(outputFilePath, tiffOptions);
tiffOptions.setFullFrame(false);
// Save as TIFF
image.save(outputFilePath1, tiffOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment