Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save openize-heic-gists/9a2763a003f35e7f2079cd8422115734 to your computer and use it in GitHub Desktop.

Select an option

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
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