You can use im4java and ImageMagick to convert heic to jpeg. The following code may help you.
public static byte[] convertHEICtoJPEG(byte[] heicBytes) throws IOException, InterruptedException, IM4JavaException {
IMOperation op = new IMOperation();
op.addImage("-");
op.addImage("jpeg:-");
File tempFile = File.createTempFile("temp", ".heic");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(heicBytes);
}
FileInputStream fis = new FileInputStream(tempFile);
Pipe pipeIn = new Pipe(fis,null);
ConvertCmd convert = new ConvertCmd();
convert.setSearchPath(IMAGE_MAGICK_PATH);
convert.setInputProvider(pipeIn);
Stream2BufferedImage s2b = new Stream2BufferedImage();
convert.setOutputConsumer(s2b);
convert.run(op);
BufferedImage image = s2b.getImage();
byte[] imageBytes = imageToBytes(image);
fis.close();
return imageBytes;
}
private static byte[] imageToBytes(BufferedImage image) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", baos);
baos.flush();
byte[] imageBytes = baos.toByteArray();
baos.close();
return imageBytes;
}