Created
April 10, 2025 15:29
-
-
Save openize-heic-gists/9a2763a003f35e7f2079cd8422115734 to your computer and use it in GitHub Desktop.
Read HEIC file into BufferedImage in Java and save it to JPEG using Java ImageIO
This file contains hidden or 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
| import java.awt.image.BufferedImage; | |
| import javax.imageio.ImageIO; | |
| import openize.heic.decoder.HeicImage; | |
| import openize.io.IOFileStream; | |
| import openize.io.IOMode; | |
| try (IOFileStream fs = new IOFileStream("filename.heic", IOMode.READ)) | |
| { | |
| HeicImage image = HeicImage.load(fs); | |
| int[] pixels = frames.get(key).getInt32Array(PixelFormat.Argb32); | |
| var width = (int)image.Width; | |
| var height = (int)image.Height; | |
| BufferedImage image2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); | |
| image2.setRGB(0, 0, width, height, pixels, 0, width); | |
| ImageIO.write(image2, "JPEG", new File("output.jpg")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment