Мне нужно выполнить это локально, используя Java, без какого-либо специального пакета или вызова внешнего API для его преобразования. До сих пор пробовал использовать пакеты twelevmonkey и рисовать пакеты. Либо пакеты недоступны, либо код, который я часто нахожу в Интернете, неверен.
ниже приведен один из кодов, которые я пробовал:
Код: Выделить всё
public class HeicToJpgConverter {
public static void main(String[] args){
try {
// Get the path to the HEIC/HEIF image file.
String heicPath = "input.heic";
// Read the image metadata.
Metadata metadata = ImageMetadataReader.readMetadata(new File(heicPath));
// Get the ExifIFD0 directory.
List exifDirectory = (List) metadata.getDirectories();
System.out.println("exifDirectory:" + exifDirectory );
System.out.println("exifDirectory size:" + exifDirectory.size() );
// Get the image width and height.+
int width = exifDirectory.get(1).getInt(ExifIFD0Directory.TAG_IMAGE_WIDTH);
int height = exifDirectory.get(1).getInt(ExifIFD0Directory.TAG_IMAGE_HEIGHT);
// Create a new JPG image with the same width and height.
BufferedImage jpgImage = new BufferedImage(255, 255, BufferedImage.TYPE_INT_RGB);
// Convert the HEIC/HEIF image to JPG.
//ImageConverter.convertHeicToJpg(heicPath, jpgImage);
// Save the JPG image.
File jpgFile = new File("output.jpg");
ImageIO.write(jpgImage, "jpg", jpgFile);
} catch (MetadataException | IOException e) {
throw new RuntimeException(e);
} catch (ImageProcessingException e) {
throw new RuntimeException(e);
}
}
Код: Выделить всё
Task :HeicToJpgConverter.main() FAILED
exifDirectory:[HEIF Directory (3 tags), HEIF Directory (2 tags), File Type Directory (4 tags), File Directory (3 tags)]
exifDirectory size:4
Exception in thread "main" java.lang.RuntimeException: com.drew.metadata.MetadataException: Tag 'Unknown tag (0x0100)' has not been set -- check using containsTag() first
at org.sample.rd.HeicToJpgConverter.main(HeicToJpgConverter.java:46)
Caused by: com.drew.metadata.MetadataException: Tag 'Unknown tag (0x0100)' has not been set -- check using containsTag() first
at com.drew.metadata.Directory.getInt(Directory.java:440)
at org.sample.rd.HeicToJpgConverter.main(HeicToJpgConverter.java:31)
Caused by: com.drew.metadata.MetadataException: Tag 'Unknown tag (0x0100)' has not been set -- check using containsTag() first
Execution failed for task ':HeicToJpgConverter.main()'.
> Process 'command 'C:/Users/raviraj.sankolli/.jdks/temurin-1.8.0_362/bin/java.exe'' finished with non-zero exit value 1
Любая помощь приветствуется
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/769 ... ge-in-java