Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. HEIC Image Conversion? Is it possible?
Forum Update on Monday, May 27th 2025

HEIC Image Conversion? Is it possible?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 5 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ebonnett
    wrote on last edited by
    #1

    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.

    ekkescornerE 1 Reply Last reply
    0
    • E ebonnett

      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.

      ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #2

      @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

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      E 1 Reply Last reply
      1
      • ekkescornerE ekkescorner

        @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

        E Offline
        E Offline
        ebonnett
        wrote on last edited by
        #3

        @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).

        ekkescornerE 1 Reply Last reply
        0
        • E ebonnett

          @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).

          ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote on last edited by
          #4

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

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.8 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Markus Goetz53
            wrote on last edited by
            #5

            This is how we do it on Qt 5.12.4 on iOS. On macOS, Qt might have a Qt image plugin for this too:

            // pseudo code adapted for forum.qt.io
            QByteArray fromHEICToJPEG(const QByteArray &imageData) {
                QBuffer buffer;
                buffer.setData(imageData);
                QImageReader imageReader(&buffer);
                qDebug() << "width"<< imageReader.size().width() << "height" << imageReader.size().height() << "format"<<imageReader.format() << imageReader.subType();
                // ^^Qt auto detects the "heic" format
                QImage resizeImage = imageReader.read();
                QByteArray outBa;
                QBuffer outBuffer(&outBa);
                outBuffer.open(QIODevice::WriteOnly);
                resizeImage.save(&outBuffer, "JPEG");
                return outBa;
            }
            
            1 Reply Last reply
            1
            • M Offline
              M Offline
              Markus Goetz53
              wrote on last edited by
              #6

              Other platforms: https://codereview.qt-project.org/c/qt/qtimageformats/+/236077

              1 Reply Last reply
              2
              • R Offline
                R Offline
                Ramport
                wrote on last edited by
                #7

                First of all,Heic only supports IOS devices,but Windows devices do not support Heic format.
                The HEIC can be converted to JPG,only then can it be supported by Windows devices.

                jsulmJ 1 Reply Last reply
                -1
                • R Ramport

                  First of all,Heic only supports IOS devices,but Windows devices do not support Heic format.
                  The HEIC can be converted to JPG,only then can it be supported by Windows devices.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Ramport said in HEIC Image Conversion? Is it possible?:

                  Heic only supports IOS devices

                  This is wrong, see "Support" and "Operating systems" https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  R 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Ramport said in HEIC Image Conversion? Is it possible?:

                    Heic only supports IOS devices

                    This is wrong, see "Support" and "Operating systems" https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format

                    R Offline
                    R Offline
                    Ramport
                    wrote on last edited by
                    #9

                    @jsulm said in HEIC Image Conversion? Is it possible?:

                    @Ramport said in HEIC Image Conversion? Is it possible?:

                    Heic only supports IOS devices

                    This is wrong, see "Support" and "Operating systems"
                    https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format
                    https://www.iseepassword.com/convert-heic-to-jpg.html

                    Thank you,but that i also added what I got here,you can convert between Heic and JPG at will, but Heic pictures cannot be supported on Windows devices unless they are converted to JPG pictures.

                    1 Reply Last reply
                    -1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved