Last active
March 25, 2021 07:57
-
-
Save aspose-com-gists/17961f60f01297fe54c8e815099c7c85 to your computer and use it in GitHub Desktop.
Convert GIF to PNG BMP JPEG TIFF in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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