HEIC Image Conversion? Is it possible?



  • The app I'm working on currently has a feature where I create a zip file, bundle a report and associated images and send the zip to someone. Many times, the images would fail to show in the pdf that gets generated. We construct html and convert to pdf, btw. After some debugging, I found that the extension of the images is HEIC. Well, I didn't know what that was until I researched.

    I know that there is a setting on iOS for saving images in either High Efficiency or Most Compatible but I'd really rather not force users to make a system wide setting change like that. Rather, I'd like to convert the images into JPG before bundling them in the zip. Is this possible?

    I'm also aware that there is a bug for this and I can apply a patch to the qtimageformats project but I'm not sure if this will offer a conversion mechanism.

    FYI, I'm using 5.11.1 and 4.7 so I'm fully up to date.


  • Qt Champions 2016

    @ebonnett seems that you have to add some native iOS code.
    found this - but not tested yet !

    NSString *heicImageFilePath = @"<file/path/to/heic/image>";
    NSString *ext = [heicImageFilePath pathExtension];
    if ([ext isEqualToString:@"heic"]) {
        
       // create new jpeg file from input heic filepath
        NSString* fname = [imageFilePath stringByDeletingPathExtension];
        NSString* newJpgPath = [fname stringByAppendingPathExtension:@"jpg"];;
        
        NSURL *url = [NSURL fileURLWithPath:imageFilePath];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *image = [UIImage imageWithData:data];
        NSData *jpgImageData = UIImageJPEGRepresentation(image, 0.7);
    
        [jpgImageData writeToFile:newJpgPath atomically:YES];
    }
    

    also take a look here



  • @ekkescorner Thanks for the tip. I wonder how long it will be before there is a built in converter? This presents a problem with emailing photos from iOS to any other platform, which my application does... unless of course you force the users to store their photos in jpg, but this is not the default behavior (nor should it be).


  • Qt Champions 2016

    @ebonnett BTW: Android 9 now also supports HEIF (HEIC)
    https://android-developers.googleblog.com/2018/08/introducing-android-9-pie.html
    conversion between JPG and HEIC can be done with
    https://developer.android.com/reference/android/graphics/ImageDecoder

    have you opened an issue for Qt to support HEIC ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.