Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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