1

I want to save a Bitmap into a *.HEIC file. When I saved a heif file and reopen it by ImageDecoder, it report those errors. I think it may because image file does not have exif data. I check Exifinterface, but it does not have constructor from Bitmap. I just want exif data contains the width and height of the image. Is there any way to construt that exif byte array or some library would help?

// save image into a heif image
HeifWriter.Builder heifBuilder = new HeifWriter.Builder(imgPath + ".HEIC", img.getWidth(),
                    img.getHeight(),
                    HeifWriter.INPUT_MODE_BITMAP);
            HeifWriter heifWriter = heifBuilder.build();
            heifWriter.start();
            heifWriter.addBitmap(img);
            if (exifData != null) {
                heifWriter.addExifData(0, exifData, 0, exifData.length);
            }
            heifWriter.stop(0);
            heifWriter.close();
// open image
public static Bitmap openImg(String imgPath) throws IOException {
        ImageDecoder.Source imgsource = ImageDecoder.createSource(new File(imgPath));
        return ImageDecoder.decodeBitmap(imgsource, (decoder, info, source) -> {
            decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE);
            decoder.setMutableRequired(true);
        });
    }
// error log
09-02 22:59:24.871 14119 14123 D FrameDecoder: FrameDecoder destroyed
09-02 22:59:24.871 14119 14123 E StagefrightMetadataRetriever: all codecs failed to extract frame.
09-02 22:59:24.871 14119 14123 E MetadataRetrieverClient: failed to extract image at index -1
09-02 22:59:24.871 22821 22914 E HeifDecoderImpl: decode: metadata is a nullptr
09-02 22:59:24.873 22821 22914 W System.err: java.io.IOException: getPixels failed with error invalid input
09-02 22:59:24.873 22821 22914 W System.err:    at android.graphics.ImageDecoder.nDecodeBitmap(Native Method)
09-02 22:59:24.873 22821 22914 W System.err:    at android.graphics.ImageDecoder.decodeBitmapInternal(ImageDecoder.java:1720)
09-02 22:59:24.873 22821 22914 W System.err:    at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1877)
09-02 22:59:24.873 22821 22914 W System.err:    at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1863)
09-02 22:59:24.873 22821 22914 W System.err:    at cn.edu.scut.ppps.Utils.openImg(Utils.java:30)
Aroc
  • 11
  • 3
  • A bitmap does not contain an exif header or exif information. So no. No exif in your file. It does not come magically. – blackapps Sep 02 '22 at 16:09
  • But you have an exifData variable. Was it null? You should instantiate that and fill with the right data. Where is that ExifData class? And how did you obtain that bitmap? – blackapps Sep 02 '22 at 16:12
  • How do I get exif byte[] that suitable for HEIC format? I check ExifInterface class and ExifData Class, they doesn`t provide toByte[] method. – Aroc Sep 03 '22 at 12:16
  • I found this [link](https://issuetracker.google.com/issues/244211253) about my question. – Aroc Sep 03 '22 at 12:23
  • I just want exif data contains the width and height of the image. Is there any way to construt that exif byte array or some library would help? – Aroc Sep 03 '22 at 12:33

0 Answers0