Post

Replies

Boosts

Views

Activity

CGImageDestinationFinalize crashed iOS15.2
I wrote the code as below for save image from PHImageManager, but a crash occurs. The data is from PHImageManager.default().requestImageDataAndOrientation. Crash Code guard let cgImage = UIImage(data: data)?.cgImage else { return } let metadata = ciImage.properties let destination: CGImageDestination = CGImageDestinationCreateWithURL(url as CFURL, uti as CFString, 1, nil)! CGImageDestinationAddImage(destination, cgImage, metadata as CFDictionary?) let success: Bool = CGImageDestinationFinalize(destination) // <- crashed Not Crash Code guard let cgImage = UIImage(data: data)?.cgImage else { return } let metadata = ciImage.properties let destination: CGImageDestination = CGImageDestinationCreateWithURL(url as CFURL, uti as CFString, 1, nil)! CGImageDestinationAddImage(destination, cgImage, nil) let success: Bool = CGImageDestinationFinalize(destination) // <- not crashed metadata { ColorModel = RGB; DPIHeight = 72; DPIWidth = 72; Depth = 8; PixelHeight = 2160; PixelWidth = 2880; ProfileName = "sRGB IEC61966-2.1"; "{Exif}" = { ApertureValue = "1.356143809255609"; BrightnessValue = "0.1278596944592232"; ColorSpace = 1; ComponentsConfiguration = ( 1, 2, 3, 0 ); CompositeImage = 2; DateTimeDigitized = "2021:12:28 08:38:28"; DateTimeOriginal = "2021:12:28 08:38:28"; DigitalZoomRatio = "1.300085984522786"; ExifVersion = ( 2, 2, 1 ); ExposureBiasValue = "0.09803208290449658"; ExposureMode = 0; ExposureProgram = 2; ExposureTime = "0.025"; FNumber = "1.6"; Flash = 16; FlashPixVersion = ( 1, 0 ); FocalLenIn35mmFilm = 33; FocalLength = "4.2"; ISOSpeedRatings = ( 400 ); LensMake = Apple; LensModel = "iPhone 12 back camera 4.2mm f/1.6"; LensSpecification = ( "4.2", "4.2", "1.6", "1.6" ); MeteringMode = 5; OffsetTime = "+09:00"; OffsetTimeDigitized = "+09:00"; OffsetTimeOriginal = "+09:00"; PixelXDimension = 2880; PixelYDimension = 2160; SceneCaptureType = 0; SceneType = 1; SensingMethod = 2; ShutterSpeedValue = "5.321697281908764"; SubjectArea = ( 2011, 1509, 2216, 1329 ); SubsecTimeDigitized = 686; SubsecTimeOriginal = 686; WhiteBalance = 0; }; "{IPTC}" = { DateCreated = 20211228; DigitalCreationDate = 20211228; DigitalCreationTime = 083828; TimeCreated = 083828; }; "{JFIF}" = { DensityUnit = 0; JFIFVersion = ( 1, 0, 1 ); XDensity = 72; YDensity = 72; }; "{TIFF}" = { DateTime = "2021:12:28 08:38:28"; HostComputer = "iPhone 12"; Make = Apple; Model = "iPhone 12"; Orientation = 0; ResolutionUnit = 2; Software = "Snowcorp SODA 5.4.8 / 15.2"; XResolution = 72; YResolution = 72; }; } What are the reasons? If I use CGimageDestinationAddImageFromSource instead of CGimageDestinationAddImage, there is no crash even if I add metadata. If I use PHImageManager.default().requestImage instead of PHImageManager.default().requestImageDataAndOrientation, and extract cgImage, there is no crash even if I add metadata.
3
0
1.8k
Dec ’21
Different information values depending on how the metadata of the image is obtained (PHAsset vs PHPickerResult)
While customizing ImagePicker and using it, we find out that the metadata is not reflected normally and report it. The situation is as follows. The time or time zone of an image is changed in the Photos app. Changing the time zone of an image with an actual capture date of 2024:11:08 08:27:44 → 2024:11:07 17:27:44 Image data is extracted from a PHAsset using PHImageManager. The metadata is obtained from this image data. The time zone information exposed in the Exif tag information does not reflect the time or time zone changed in the Photos app. let asset: PHAsset = ... .... let options = PHImageRequestOptions() options.isSynchronous = true options.version = .current options.deliveryMode = .highQualityFormat options.resizeMode = .none options.normalizedCropRect = .zero options.isNetworkAccessAllowed = true options.progressHandler = { progress, error, _, _ in } PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { imageData, uti, orientation, info in let cgImageSource = CGImageSourceCreateWithData(imageData! as CFData, nil) let properties = CGImageSourceCopyPropertiesAtIndex(cgImageSource!, 0, nil) as? Dictionary&lt;String, Any&gt; let exif = properties!["{Exif}"] let dictionary = exif as? Dictionary&lt;String, Any&gt; } Metadata Check In this case, it is reflected in the creationDate of PHAsset, so it can be somewhat compensated by forcibly replacing the metadata. However, because PHAsset does not include time zone information, when changing the time zone as well, it's impossible to calculate the correct time according to the time zone. PHPicker This issue is resolved when using the PHPickerResult provided by PHPicker. extension PhotosPickerViewController: PHPickerViewControllerDelegate { public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { ..... for result in results { let identifier = UTType.image.identifier if result.itemProvider.hasItemConformingToTypeIdentifier(identifier) { result.itemProvider.loadDataRepresentation(forTypeIdentifier: identifier) { data, error in guard let data = data, let cgImageSource = CGImageSourceCreateWithData(data as CFData, nil), let properties = CGImageSourceCopyPropertiesAtIndex(cgImageSource, 0, nil) as? Dictionary&lt;String, Any&gt;, let exif = properties["{Exif}"], let dictionary = exif as? Dictionary&lt;String, Any&gt; else { return } } } } } } Metadata Check Question I wonder why this happens, and if this is normal behavior. Instead of the System Picker that Apple provides as a base, I wonder if there is any way I can supplement it in that situation if I use a customizer.
0
0
557
Nov ’24