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.
-
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.
@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
-
@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).
-
@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).
@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/ImageDecoderhave you opened an issue for Qt to support HEIC ?
-
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; }
-
Other platforms: https://codereview.qt-project.org/c/qt/qtimageformats/+/236077
-
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.@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
-
@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
@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.htmlThank 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.