Image I/O

RSS for tag

Read and write most image file formats, manage color, access image metadata using Image I/O.

Posts under Image I/O tag

200 Posts

Post

Replies

Boosts

Views

Activity

EDR support for images
More and more iOS devices can capture content with high/extended dynamic range (HDR/EDR) now, and even more devices have screens that can display that content properly. Apple also gave us developers the means to correctly display and process this EDR content in our apps on macOS and now also on iOS 16. There are a lot of EDR-related sessions from WWDC 2021 and 2022. However, most of them focus on HDR video but not images—even though Camera captures HDR images by default on many devices. Interestingly, those HDR images seem to use a proprietary format that relies on EXIF metadata and an embedded HDR gain map image for displaying the HDR effect in Photos. Some observations: Only Photos will display those metadata-driven HDR images in their proper brightness range. Files, for instance, does not. Photos will not display other HDR formats like OpenEXR or HEIC with BT.2100-PQ color space in their proper brightness. When using the PHPicker, it will even automatically tone-map the EDR values of OpenEXR images to SDR. The only way to load those images is to request the original image via PHAsset, which requires photo library access. And here comes my main point: There is no API that enables us developers to load iPhone HDR images (with metadata and gain map) that will decode image + metadata into EDR pixel values. That means we cannot display and edit those images in our app the same way as Photos. There are ways to extract and embed the HDR gain maps from/into images using Image I/O APIs. But we don't know the algorithm used to blend the gain map with the image's SDR pixel values to get the EDR result. It would be very helpful to know how decoding and encoding from SDR + gain map to HDR and back works. Alternatively (or in addition), it would be great if common image loading APIs like Image I/O and Core Image would provide APIs to load those images into an EDR image representation (16-bit float linear sRGB with extended values, for example) and write EDR images into SDR + gain map images so that they are correctly displayed in Photos. Thanks for your consideration! We really want to support HDR content in our image editing apps, but without the proper APIs, we can only guess how image HDR works on iOS.
2
8
2.5k
Sep ’22
Crash in SVGFilterPrimitive::draw on iOS 16
We have suddenly started seeing this crashing stack on iOS 16. Does anyone have any workarounds? 0 libsystem_platform.dylib _platform_memmove + 420 arrow_right 1 vImage vImageCopyBuffer + 824 2 libCGInterfaces.dylib _vImageCreateCGImageFromBuffer + 2368 3 CoreSVG CIImage* SVGFilterPrimitive::inputImage<CIImage>(SVGAtom::Name) const + 88 4 CoreSVG SVGFilterPrimitive::drawFeComposite() const + 72 5 CoreSVG SVGFilterPrimitive::selectPrimitive() const + 280 6 CoreSVG SVGFilterPrimitive::draw(FilterContext&, FilterResult**, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, FilterResult*, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, FilterResult*> > >&, CGSize, CGSize) + 72
0
0
986
Aug ’22
Cannot Use Instance Member Within Property initializer
I'm trying to encode an image when this error occurred Cannot use instance member 'image' within property initializer; property initializers run before 'self' is available And having not ran into this before and the error not having a fix button like others, I was puzzled so I came here for help import UIKit class ViewController: UIViewController {   @IBOutlet weak var myImageView: UIImageView!       let image = UIImage(named: "image.png")   let imageData:NSData = UIImagePNGRepresentation(image!)! as NSData //Error is here!       override func viewDidLoad() {     super.viewDidLoad()   } }
1
1
2.2k
Aug ’22
Matrix of hardware and OS versions regarding UIImage webp support
We would like to switch our backend image pipeline to webp as it offers better quality/compression for our assets. This works nicely for combinations of modern OS versions and modern hardware, but it didn't work for me with tvOS 15 and Apple TV. I know that it's possible to check for h265 video decoding support with code like VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC) - is there something similar for checking of webp support? Or is there any documentation which gives me a matrix of hardware/software combinations supporting webp? I would be interested in hardware running iOS and tvOS. Stefan
0
0
981
Aug ’22
Image in scnview is darker than in other view
Hello developers, I have a original image that is ordinary one. and set image in image view like this imageview.image = UIImage(cgImage: image) result is this, and then set same image in scenekit like this scnview.scene.background.contents = image and result is, I use same image to two othre view, and one in scnview is darker than original one, and I don't know the problem... found in google, who has a same problem, but there is no answer. (https://stackoverflow.com/questions/60679819/adding-uiimageview-to-arscnview-scene-background-causes-saturation-hue-to-be-off) checked scnview's pixelformat it was bgra8unorm. What's the problem??
0
0
904
Jul ’22
CompositeImage is always 2 for images acquired using AVCapturePhotoOutput
I use AVCapturePhotoOutput to take still pictures. I print metadata with the following code. func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {     guard let data = photo.fileDataRepresentation() else { return }     let ciImage = CIImage(data: data)     print(ciImage?.properties) The following CompositeImage can be obtained CompositeImage = 2 However, CompositeImage will always be 2 even if HDR is turned off as shown below. device.automaticallyAdjustsVideoHDREnabled = false device.isVideoHDREnabled = false The expected value is 1. Could you find the cause of this?
0
0
1.8k
Jun ’22
Export SwiftUI View
I know this is a strange and easy question. but JUST CANT FIND ANY REFERENCE aaaaaaaa I'm using SwiftUI and wants to export to PDF (best I can find Creating PDFs on MacOS without UIKit) export to image export to HTML export to everything possible etc BONUS print the page I can only find UIKit support and they are all outdated. AND IF POSSIBLE how to integrate ShareLink to share these(PDF, Image, HTML, etc) and write them onto disk using NSSavePane? even better how to do this on a of the platforms (I know I'm greedy😂) Thanks for any help🙏
0
0
863
Jun ’22
CGImageCreate API returns nil in some cases on iOS 16 beta version
Since the release of iOS 16, many users of our app had complained that many WebP images in our App broken suddenly which made the app unusable. We are using google's WebP library to decode WebP data. We create a CGDataProviderRef with WebPDecoderConfig output using MODE_RGB colorspace and feed it to CGImageCreate. On iOS 16 beta version, It just returns nil which is unexpected. Only if we use WebPDecoderConfig with MODE_rgbA, it works correctly and return a valid image ref. However, on iOS systems before iOS 16, it works correctly with the exactly same image. Does apple will fix this issue?
1
1
1.7k
Jun ’22
Receiving this error 'EXC_BREAKPOINT (code=1, subcode=0x1051904b8)' when trying to use a PhotoPicker.
I'm going insane over this, I'm using Xcode 13 beta 6 on the M1 MacBook Air. Every time I pick an image, I receive this error message. At this point I don't know what I can do because the message is so vague. Please help me.     @Binding var image: UIImage          func makeUIViewController(context: Context) -> UIImagePickerController {         let imagePicker = UIImagePickerController()         imagePicker.delegate = context.coordinator         return imagePicker     }          func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {              }          func makeCoordinator() -> Coordinator {         Coordinator(parent: self)     }          final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {                   var parent: PhotoPicker                  init(parent: PhotoPicker){             self.parent = parent         }                  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {             if let image = info[.originalImage] as? UIImage {                 parent.image = image             }else{                              }             picker.dismiss(animated: true, completion: nil)         }     } }          @State private var isPresented: Bool = false     @State private var avatarImage = UIImage(systemName: "person") ?? UIImage()          var body: some View {         VStack {             Image(uiImage: avatarImage)                 .resizable()                 .scaledToFill()                 .frame(width: 150, height: 150)                 .clipShape(Circle())                 .padding()                 .onTapGesture {                     isPresented = true                 }                          Spacer()         }         .navigationTitle("Profile")         .sheet(isPresented: $isPresented) {             PhotoPicker(image: $avatarImage)         }     } }
4
0
5.4k
May ’22
Exifs are not saved properly with Image
In my Xamarin iOS App (iOS 15 and later) i tried to save Exifdata in the dictionary with CGImageDestination.Create() and add there the changed Metadata. The data is displayed in the right way in the console, but after saving it with NSData.Save the data is not in the exif anymore, if i write it on the console. I tried changing the CGImageProperties.ExifUserComment and TIFFImageDescription, but both are not saved. Is there any limitation, on which exifdata can be saved or am i doing something wrong? Here is my example code, where i change the existing metadata, set it to the exifdictionary and then save it with NSData.Save(). var img = UIImage.FromFile(file); NSData ns = img.AsJPEG(); var dicMetadata = ns.ExtractMetaDataFromImageData(); NSMutableDictionary dicDescription = (NSMutableDictionary)dicMetadata.ObjectForKey(ImageIO.CGImageProperties.ExifDictionary); if (dicDescription == null) { dicDescription = new NSMutableDictionary(); } dicDescription.SetValueForKey(FromObject(bf.name.Trim()), ImageIO.CGImageProperties.ExifUserComment); dicMetadata.SetValueForKey(dicDescription, ImageIO.CGImageProperties.ExifDictionary); File.Delete(file); var imgSrc = ImageIO.CGImageSource.FromData(ns); var outImageData = new NSMutableData(); using (var d = ImageIO.CGImageDestination.Create(outImageData, imgSrc.TypeIdentifier, 1, new ImageIO.CGImageDestinationOptions())) { if(d==null) { Console.Write("could not generate dest"); } d.AddImage(imgSrc, 0, dicMetadata); d.Close() } NSError writeError; var imageSaved = outImageData.Save(file, NSDataWritingOptions.Atomic, out writeError);
0
0
1.1k
May ’22
CGImageDestinationCopyImageSource converts or truncates floats to integers
Some EXIF entries require float content as a string. For example FNumber often looks like that: "2.8" or "1.4". When I edit EXIF data using CGImageDestinationCopyImageSource most of the EXIF entries that require that float-like content are truncated to their first character. To stay in the example above the EXIF dict will be written with a "2" or "1". The dot and the rest of the string are truncated. 🤯 Shall: "2.8" Is: "2" All EXIF data is written correctly (I use about 40 fields), but only the following keys are reduced to some kind of integer style: kCGImagePropertyExifFNumber kCGImagePropertyExifFocalLength kCGImagePropertyGPSAltitude kCGImagePropertyGPSImgDirection kCGImagePropertyGPSSpeed I am using this code to set the entries: let metaData = CGImageMetadataCreateMutable() if !CGImageMetadataSetValueMatchingImageProperty(metaData, kCGImagePropertyExifDictionary, kCGImagePropertyExifFNumber, 2.8 as CFTypeRef) { print("kCGImagePropertyExifFNumber EXIF not written") } let destOptions: [String: AnyObject] = [ kCGImageDestinationMergeMetadata as String: NSNumber(value: 1), kCGImageDestinationMetadata as String: metaData ] if !CGImageDestinationCopyImageSource(destination, cgImgSource, destOptions as CFDictionary, nil) { print("Error making CGImageDestinationCopyImageSource") } The dictionary being created shows me the correct values, but when I open the updated JPG, I only see the truncated floating point numbers. I tried it with 2.8 as CFString "2.8" as CFString 2.8 as CFTypeRef "2.8" as CFTypeRef 2.8 as CFNumber 2.8 as NSNumber 2.8 as NSString Only in kCGImagePropertyGPSLongitude & kCGImagePropertyGPSLatitude this behavior doesn't occur. if !CGImageMetadataSetValueMatchingImageProperty(metaData, kCGImagePropertyGPSDictionary, kCGImagePropertyGPSLatitude, 53.997853 as CFTypeRef ) { print("kCGImagePropertyGPSLatitude GPS not written") } Using CGImageDestinationCreateWithData does not do this and writes the data correctly. I think that’s strange, because most photos aren’t taken with int-values. So either I found a bug or I am doing something wrong. What’s the point here? Is there some kind of round-rule?
0
0
716
May ’22
Cannot preview most JPEG files from Files app
I have recently purchased an iPhone coming from Android and placed all my documents on iCloud. When using the File app, I tap on some JPEG files in my Documents folder. They will fase about 5 times, each time if flashes it shows the image briefly, however, after that no image is shown. Sometimes they do not even flash, Files app will only show the loader and the word LOADING right below it, and no preview is shown. iOS version is 15.4.1. One thing that differentiates one file with a problem and file without problems is the file size. My JPEG with issues on my physical device are way larger at the order of 20 to 60 MB. If I pretend to share the file and save to iPhone instead, I can view it normally from Photos app, but these are document images I do not want to have in Photos because they belong to a folder with other document types as well, for the sake of organization. Interestingly, on my MacBook Pro, I open an iOS simulator, in this case, a 15.4 iPod Touch and follow exactly the same steps, and all JPEG files are shown in Files app preview without any issues. This is an annoying bug as I had personal issues for not being able to open my image document when I needed and because such a pricey product like an iPhone should not produce such a bug for such a basic thing like showing a JPEG file. These files are not corrupt in any way as I can open them normally if using Photos or on my MacBook Pro, or everywhere else including the simulator in previous iOS release, the Photos app or an Android device.
0
0
1.3k
May ’22
Built in flood fill (bucket tool) ability for UIImage or CGImage?
Hi. I'd like to be able to do a flood fill on images, either UIImage or CGImage, and was wondering if there was a built in way to do this provided by Apple's standard frameworks? i.e. Take a bitmap image and specify a point and color and then make it fill the area with that color, no matter what shape it is. I've seen a few examples of algorithm code to do this, but they're quite large and complicated so am trying to avoid them.
0
0
1.1k
Mar ’22
EDR support for images
More and more iOS devices can capture content with high/extended dynamic range (HDR/EDR) now, and even more devices have screens that can display that content properly. Apple also gave us developers the means to correctly display and process this EDR content in our apps on macOS and now also on iOS 16. There are a lot of EDR-related sessions from WWDC 2021 and 2022. However, most of them focus on HDR video but not images—even though Camera captures HDR images by default on many devices. Interestingly, those HDR images seem to use a proprietary format that relies on EXIF metadata and an embedded HDR gain map image for displaying the HDR effect in Photos. Some observations: Only Photos will display those metadata-driven HDR images in their proper brightness range. Files, for instance, does not. Photos will not display other HDR formats like OpenEXR or HEIC with BT.2100-PQ color space in their proper brightness. When using the PHPicker, it will even automatically tone-map the EDR values of OpenEXR images to SDR. The only way to load those images is to request the original image via PHAsset, which requires photo library access. And here comes my main point: There is no API that enables us developers to load iPhone HDR images (with metadata and gain map) that will decode image + metadata into EDR pixel values. That means we cannot display and edit those images in our app the same way as Photos. There are ways to extract and embed the HDR gain maps from/into images using Image I/O APIs. But we don't know the algorithm used to blend the gain map with the image's SDR pixel values to get the EDR result. It would be very helpful to know how decoding and encoding from SDR + gain map to HDR and back works. Alternatively (or in addition), it would be great if common image loading APIs like Image I/O and Core Image would provide APIs to load those images into an EDR image representation (16-bit float linear sRGB with extended values, for example) and write EDR images into SDR + gain map images so that they are correctly displayed in Photos. Thanks for your consideration! We really want to support HDR content in our image editing apps, but without the proper APIs, we can only guess how image HDR works on iOS.
Replies
2
Boosts
8
Views
2.5k
Activity
Sep ’22
How to convert 10-bit HEIC image to 16-bit PNG with Image I/O on macOS?
I'm trying to convert a 10-bit HEIC image to a 16-bit PNG, but it ends up 8-bit PNG. Is there any way to force it to be 16-bit? I'm using CGImageSourceCreateWithURL on macOS.
Replies
2
Boosts
0
Views
1.8k
Activity
Sep ’22
Flickering issues when running iOS apps
When GL.Clear is used in Unityios, and flashes outside the first two areas as shown in the image of the link. [link] https://youtu.be/ssjkWWs0-4Q Is it related to Addressable? I'm asking you to borrow your knowledge because I don't have any data when I search, and it seems to be a problem that didn't happen anywhere else.
Replies
0
Boosts
0
Views
752
Activity
Sep ’22
Crash in SVGFilterPrimitive::draw on iOS 16
We have suddenly started seeing this crashing stack on iOS 16. Does anyone have any workarounds? 0 libsystem_platform.dylib _platform_memmove + 420 arrow_right 1 vImage vImageCopyBuffer + 824 2 libCGInterfaces.dylib _vImageCreateCGImageFromBuffer + 2368 3 CoreSVG CIImage* SVGFilterPrimitive::inputImage<CIImage>(SVGAtom::Name) const + 88 4 CoreSVG SVGFilterPrimitive::drawFeComposite() const + 72 5 CoreSVG SVGFilterPrimitive::selectPrimitive() const + 280 6 CoreSVG SVGFilterPrimitive::draw(FilterContext&, FilterResult**, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, FilterResult*, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, FilterResult*> > >&, CGSize, CGSize) + 72
Replies
0
Boosts
0
Views
986
Activity
Aug ’22
How to get the filters in VNDocumentCameraViewController without open a camara?
There are 4 filters in VNDocumentCameraViewController, "Color", "Grayscal", "Black & White", "Photo". Is there a way to apply the filters on UIImages directly without open a camara?
Replies
1
Boosts
1
Views
1.2k
Activity
Aug ’22
Cannot Use Instance Member Within Property initializer
I'm trying to encode an image when this error occurred Cannot use instance member 'image' within property initializer; property initializers run before 'self' is available And having not ran into this before and the error not having a fix button like others, I was puzzled so I came here for help import UIKit class ViewController: UIViewController {   @IBOutlet weak var myImageView: UIImageView!       let image = UIImage(named: "image.png")   let imageData:NSData = UIImagePNGRepresentation(image!)! as NSData //Error is here!       override func viewDidLoad() {     super.viewDidLoad()   } }
Replies
1
Boosts
1
Views
2.2k
Activity
Aug ’22
Matrix of hardware and OS versions regarding UIImage webp support
We would like to switch our backend image pipeline to webp as it offers better quality/compression for our assets. This works nicely for combinations of modern OS versions and modern hardware, but it didn't work for me with tvOS 15 and Apple TV. I know that it's possible to check for h265 video decoding support with code like VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC) - is there something similar for checking of webp support? Or is there any documentation which gives me a matrix of hardware/software combinations supporting webp? I would be interested in hardware running iOS and tvOS. Stefan
Replies
0
Boosts
0
Views
981
Activity
Aug ’22
Live Photo wallpaper
In iOS 16 beta 2 the live wallpaper feature is removed. I feel that this is something that should be kept an option or can be done with a different gesture.
Replies
0
Boosts
1
Views
591
Activity
Jul ’22
Image in scnview is darker than in other view
Hello developers, I have a original image that is ordinary one. and set image in image view like this imageview.image = UIImage(cgImage: image) result is this, and then set same image in scenekit like this scnview.scene.background.contents = image and result is, I use same image to two othre view, and one in scnview is darker than original one, and I don't know the problem... found in google, who has a same problem, but there is no answer. (https://stackoverflow.com/questions/60679819/adding-uiimageview-to-arscnview-scene-background-causes-saturation-hue-to-be-off) checked scnview's pixelformat it was bgra8unorm. What's the problem??
Replies
0
Boosts
0
Views
904
Activity
Jul ’22
I want to add GPS location data to Exif of UIImage
I want to add GPS location data to Exif of UIImage GPS location data as Exif information in UIImage I want to give latitude and longitude. How should I implement it?
Replies
1
Boosts
0
Views
1.9k
Activity
Jun ’22
kCGImagePropertyExifSourceImageNumberOfCompositeImage
I want to store the number of images being composited with HDR in kCGImagePropertyExifSourceImageNumberOfCompositeImage. But I don't know how to get the composite number. Could you please tell me how to do that?
Replies
0
Boosts
0
Views
665
Activity
Jun ’22
CompositeImage is always 2 for images acquired using AVCapturePhotoOutput
I use AVCapturePhotoOutput to take still pictures. I print metadata with the following code. func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {     guard let data = photo.fileDataRepresentation() else { return }     let ciImage = CIImage(data: data)     print(ciImage?.properties) The following CompositeImage can be obtained CompositeImage = 2 However, CompositeImage will always be 2 even if HDR is turned off as shown below. device.automaticallyAdjustsVideoHDREnabled = false device.isVideoHDREnabled = false The expected value is 1. Could you find the cause of this?
Replies
0
Boosts
0
Views
1.8k
Activity
Jun ’22
Export SwiftUI View
I know this is a strange and easy question. but JUST CANT FIND ANY REFERENCE aaaaaaaa I'm using SwiftUI and wants to export to PDF (best I can find Creating PDFs on MacOS without UIKit) export to image export to HTML export to everything possible etc BONUS print the page I can only find UIKit support and they are all outdated. AND IF POSSIBLE how to integrate ShareLink to share these(PDF, Image, HTML, etc) and write them onto disk using NSSavePane? even better how to do this on a of the platforms (I know I'm greedy😂) Thanks for any help🙏
Replies
0
Boosts
0
Views
863
Activity
Jun ’22
CGImageCreate API returns nil in some cases on iOS 16 beta version
Since the release of iOS 16, many users of our app had complained that many WebP images in our App broken suddenly which made the app unusable. We are using google's WebP library to decode WebP data. We create a CGDataProviderRef with WebPDecoderConfig output using MODE_RGB colorspace and feed it to CGImageCreate. On iOS 16 beta version, It just returns nil which is unexpected. Only if we use WebPDecoderConfig with MODE_rgbA, it works correctly and return a valid image ref. However, on iOS systems before iOS 16, it works correctly with the exactly same image. Does apple will fix this issue?
Replies
1
Boosts
1
Views
1.7k
Activity
Jun ’22
Receiving this error 'EXC_BREAKPOINT (code=1, subcode=0x1051904b8)' when trying to use a PhotoPicker.
I'm going insane over this, I'm using Xcode 13 beta 6 on the M1 MacBook Air. Every time I pick an image, I receive this error message. At this point I don't know what I can do because the message is so vague. Please help me.     @Binding var image: UIImage          func makeUIViewController(context: Context) -> UIImagePickerController {         let imagePicker = UIImagePickerController()         imagePicker.delegate = context.coordinator         return imagePicker     }          func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {              }          func makeCoordinator() -> Coordinator {         Coordinator(parent: self)     }          final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {                   var parent: PhotoPicker                  init(parent: PhotoPicker){             self.parent = parent         }                  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {             if let image = info[.originalImage] as? UIImage {                 parent.image = image             }else{                              }             picker.dismiss(animated: true, completion: nil)         }     } }          @State private var isPresented: Bool = false     @State private var avatarImage = UIImage(systemName: "person") ?? UIImage()          var body: some View {         VStack {             Image(uiImage: avatarImage)                 .resizable()                 .scaledToFill()                 .frame(width: 150, height: 150)                 .clipShape(Circle())                 .padding()                 .onTapGesture {                     isPresented = true                 }                          Spacer()         }         .navigationTitle("Profile")         .sheet(isPresented: $isPresented) {             PhotoPicker(image: $avatarImage)         }     } }
Replies
4
Boosts
0
Views
5.4k
Activity
May ’22
Exifs are not saved properly with Image
In my Xamarin iOS App (iOS 15 and later) i tried to save Exifdata in the dictionary with CGImageDestination.Create() and add there the changed Metadata. The data is displayed in the right way in the console, but after saving it with NSData.Save the data is not in the exif anymore, if i write it on the console. I tried changing the CGImageProperties.ExifUserComment and TIFFImageDescription, but both are not saved. Is there any limitation, on which exifdata can be saved or am i doing something wrong? Here is my example code, where i change the existing metadata, set it to the exifdictionary and then save it with NSData.Save(). var img = UIImage.FromFile(file); NSData ns = img.AsJPEG(); var dicMetadata = ns.ExtractMetaDataFromImageData(); NSMutableDictionary dicDescription = (NSMutableDictionary)dicMetadata.ObjectForKey(ImageIO.CGImageProperties.ExifDictionary); if (dicDescription == null) { dicDescription = new NSMutableDictionary(); } dicDescription.SetValueForKey(FromObject(bf.name.Trim()), ImageIO.CGImageProperties.ExifUserComment); dicMetadata.SetValueForKey(dicDescription, ImageIO.CGImageProperties.ExifDictionary); File.Delete(file); var imgSrc = ImageIO.CGImageSource.FromData(ns); var outImageData = new NSMutableData(); using (var d = ImageIO.CGImageDestination.Create(outImageData, imgSrc.TypeIdentifier, 1, new ImageIO.CGImageDestinationOptions())) { if(d==null) { Console.Write("could not generate dest"); } d.AddImage(imgSrc, 0, dicMetadata); d.Close() } NSError writeError; var imageSaved = outImageData.Save(file, NSDataWritingOptions.Atomic, out writeError);
Replies
0
Boosts
0
Views
1.1k
Activity
May ’22
CGImageDestinationCopyImageSource converts or truncates floats to integers
Some EXIF entries require float content as a string. For example FNumber often looks like that: "2.8" or "1.4". When I edit EXIF data using CGImageDestinationCopyImageSource most of the EXIF entries that require that float-like content are truncated to their first character. To stay in the example above the EXIF dict will be written with a "2" or "1". The dot and the rest of the string are truncated. 🤯 Shall: "2.8" Is: "2" All EXIF data is written correctly (I use about 40 fields), but only the following keys are reduced to some kind of integer style: kCGImagePropertyExifFNumber kCGImagePropertyExifFocalLength kCGImagePropertyGPSAltitude kCGImagePropertyGPSImgDirection kCGImagePropertyGPSSpeed I am using this code to set the entries: let metaData = CGImageMetadataCreateMutable() if !CGImageMetadataSetValueMatchingImageProperty(metaData, kCGImagePropertyExifDictionary, kCGImagePropertyExifFNumber, 2.8 as CFTypeRef) { print("kCGImagePropertyExifFNumber EXIF not written") } let destOptions: [String: AnyObject] = [ kCGImageDestinationMergeMetadata as String: NSNumber(value: 1), kCGImageDestinationMetadata as String: metaData ] if !CGImageDestinationCopyImageSource(destination, cgImgSource, destOptions as CFDictionary, nil) { print("Error making CGImageDestinationCopyImageSource") } The dictionary being created shows me the correct values, but when I open the updated JPG, I only see the truncated floating point numbers. I tried it with 2.8 as CFString "2.8" as CFString 2.8 as CFTypeRef "2.8" as CFTypeRef 2.8 as CFNumber 2.8 as NSNumber 2.8 as NSString Only in kCGImagePropertyGPSLongitude & kCGImagePropertyGPSLatitude this behavior doesn't occur. if !CGImageMetadataSetValueMatchingImageProperty(metaData, kCGImagePropertyGPSDictionary, kCGImagePropertyGPSLatitude, 53.997853 as CFTypeRef ) { print("kCGImagePropertyGPSLatitude GPS not written") } Using CGImageDestinationCreateWithData does not do this and writes the data correctly. I think that’s strange, because most photos aren’t taken with int-values. So either I found a bug or I am doing something wrong. What’s the point here? Is there some kind of round-rule?
Replies
0
Boosts
0
Views
716
Activity
May ’22
Cannot preview most JPEG files from Files app
I have recently purchased an iPhone coming from Android and placed all my documents on iCloud. When using the File app, I tap on some JPEG files in my Documents folder. They will fase about 5 times, each time if flashes it shows the image briefly, however, after that no image is shown. Sometimes they do not even flash, Files app will only show the loader and the word LOADING right below it, and no preview is shown. iOS version is 15.4.1. One thing that differentiates one file with a problem and file without problems is the file size. My JPEG with issues on my physical device are way larger at the order of 20 to 60 MB. If I pretend to share the file and save to iPhone instead, I can view it normally from Photos app, but these are document images I do not want to have in Photos because they belong to a folder with other document types as well, for the sake of organization. Interestingly, on my MacBook Pro, I open an iOS simulator, in this case, a 15.4 iPod Touch and follow exactly the same steps, and all JPEG files are shown in Files app preview without any issues. This is an annoying bug as I had personal issues for not being able to open my image document when I needed and because such a pricey product like an iPhone should not produce such a bug for such a basic thing like showing a JPEG file. These files are not corrupt in any way as I can open them normally if using Photos or on my MacBook Pro, or everywhere else including the simulator in previous iOS release, the Photos app or an Android device.
Replies
0
Boosts
0
Views
1.3k
Activity
May ’22
Built in flood fill (bucket tool) ability for UIImage or CGImage?
Hi. I'd like to be able to do a flood fill on images, either UIImage or CGImage, and was wondering if there was a built in way to do this provided by Apple's standard frameworks? i.e. Take a bitmap image and specify a point and color and then make it fill the area with that color, no matter what shape it is. I've seen a few examples of algorithm code to do this, but they're quite large and complicated so am trying to avoid them.
Replies
0
Boosts
0
Views
1.1k
Activity
Mar ’22
Render MTKView with different Colorspace
Is it possible to render an MTKView in different color spaces? For example, if I want to render it in CMYK, is there a way to adjust the colors on every frame to that colorspace before presenting it on the screen, or is that something that needs to be handled in a shader?
Replies
3
Boosts
0
Views
2.2k
Activity
Mar ’22