Photos and Imaging

RSS for tag

Integrate still images and other forms of photography into your apps.

Posts under Photos and Imaging tag

76 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Photos App: Re-indexing of edited photos
I would like to use a third-party app to edit the metadata of a photo to change its Caption and then be able to search in the Photos app to find that image with the edited caption. I have managed to do this by duplicating the photo with the edited metadata. The Photos app recognizes it as a new photo and indexes it with the new caption, making it searchable. However, when editing the photo in-place, the Photos app will not re-index the photo, therefore it will not be searchable. Is there a way to edit photos in-place and have them searchable with the new metadata?
1
0
630
Sep ’23
iPhone 14 Pro Max produces corrupted images
My iPhone produces corrupted images under certain conditions. If I shoot same scene (with slightly varying angle) in same lightning conditions, I almost all the time receive corrupted photo, which contains magenta copy of image and green rectangle. If I add some other objects to the scene, thus changing overall brightness of the scene, chance of bug reduces significantly. Device info: iPhone 14 Pro Max (iOS 17 RC), iPhone 14 Pro (iOS 17 beta 6) Images with issue: f/1.664, 1/25s, ISO 500, digitalZoom=1.205, brightness=-0.568 f/1.664, 1/25s, ISO 500, digitalZoom=1.205, brightness=-0.514 f/1.664, 1/25s, ISO 640, digitalZoom=1.205, brightness=-0.641 f/1.664, 1/25s, ISO 500, digitalZoom=1.205, brightness=-0.448 f/1.664, 1/25s, ISO 500, digitalZoom=1.205, brightness=-0.132 Images without issue: f/1.664, 1/25s, ISO 500, digitalZoom=1.205, brightness=-0.456 f/1.664, 1/20s, ISO 640, digitalZoom=1.205, brightness=-1.666 f/1.664, 1/100s, ISO 50, digitalZoom=1.205, brightness=4.840 f/1.664, 1/25s, ISO 640, digitalZoom=1.205, brightness=-0.774 I'm using builtInWideAngleCamera with continuousAutoExposure, continuousAutoFocus and slight videoZoomFactor func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { if let error = error { capturePhotoCallback?(.failure(.internalError(error.localizedDescription))) return } guard let data = photo.fileDataRepresentation() else { capturePhotoCallback?(.failure(.internalError("Can not get data representation."))) return } guard let image = UIImage(data: data) else { capturePhotoCallback?(.failure(.internalError("Can not get image from data representation."))) return } capturePhotoCallback?(.success(image)) }
0
0
480
Sep ’23
PhotosPicker delay
struct ImageTest: View { @State private var selectedPhotos: [PhotosPickerItem] = [] @State private var photosData: [Data] = [] @State private var text: String = "" var body: some View { NavigationStack{ Form { Section { HStack { PhotosPicker(selection: $selectedPhotos, maxSelectionCount: 10, matching: .images, photoLibrary: .shared()) { AddPhotoIcon(numOfImages: photosData.count) } .task(id: selectedPhotos) { for selectedPhoto in selectedPhotos { if let data = try? await selectedPhoto.loadTransferable(type: Data.self) { self.photosData.append(data) } } self.selectedPhotos = [] } if !photosData.isEmpty { ScrollView(.horizontal) { HStack { ForEach(photosData, id: \.self) { data in if let image = UIImage(data: data) { Image(uiImage: image) .resizable() .scaledToFill() .frame(width: 50, height: 50) } } } } } Spacer() } } Section { TextField("Any", text: $text) } } } } } Here with SwiftData I'm making the model that contains images and title. There is a delay when entering just ten-character text after selecting photos for like 2~3 seconds. In the debug the memory usage it soars to 700MB. How can I improve it?
1
0
578
Sep ’23
PHPicker fails to load RAW images
We observed that the PHPicker is unable to load RAW images captured on an iPhone in some scenarios. And it is also somehow related to iCloud. Here is the setup: The PHPickerViewController is configured with preferredAssetRepresentationMode = .current to avoid transcoding. The image is loaded from the item provider like this: if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage) { itemProvider.loadFileRepresentation(forTypeIdentifier: kUTTypeImage) { url, error in // work } } This usually works, also for RAW images. However, when trying to load a RAW image that has just been captured with the iPhone, the loading fails with the following errors on the console: [claims] 43A5D3B2-84CD-488D-B9E4-19F9ED5F39EB grantAccessClaim reply is an error: Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x2804a8e70 {Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 19420 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 19420 on anonymousListener or serviceListener}}} Error copying file type public.image. Error: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.image" UserInfo={NSLocalizedDescription=Cannot load representation of type public.image, NSUnderlyingError=0x280480540 {Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x2804a8e70 {Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 19420 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 19420 on anonymousListener or serviceListener}}}}} We observed that on some devices, loading the image will actually work after a short time (~30 sec), but on others it will always fail. We think it is related to iCloud Photos: On the device that has iCloud Photos sync enabled, the picker is able to load the image right after it was synced to the cloud. On devices that don't sync the image, loading always fails. It seems that the sync process is doing some processing (?) of the image that will later enable the picker to load it successfully, but that's just guessing. Additional observations: This seems to only occur for images that were taken with the stock Camera app. When using Halide to capture RAW (either ProRAW or RAW), the Picker is able to load the image. When trying to load the image as kUTTypeRawImage instead of kUTTypeImage, it also fails. The picker also can't load RAW images that were AirDroped from another device, unless it synced to iCloud first. This is reproducable using the Selecting Photos and Videos in iOS sample code project. We observed this happening in other apps that use the PHPicker, not just ours. Is this a bug, or is there something that we are missing?
5
1
1.8k
Sep ’23
Understanding PHPickerConfiguration.AssetRepresentationMode.current
The documentation for this API mentions: The system uses the current representation and avoids transcoding, if possible. What are the scenarios in which transcoding takes place? The reason for asking is that we've had a user reaching out saying they selected a video file from their Photos app, which resulted in a decrease in size from ~110MB to 35MB. We find it unlikely it's transcoding-related, but we want to gain more insights into the possible scenarios.
3
1
599
Sep ’23
PhotoKit - non-system library
Hi, I'm wondering if it is possible to manipulate the "other" Photos library with PhotoKit, not the only System one. PhotoKit documentation only mentioned object of PHPhotoLibrary class, which is "a shared object that manages access and changes to the user’s shared photo library". But the Photos app in macOS allows to create and switch between multiple photo libraries. Thanks.
2
2
696
Sep ’23
{Error Domain=PHPhotosErrorDomain Code=3305 "(null)"}
When I used BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([pathUrl path]); if (compatible) { UISaveVideoAtPathToSavedPhotosAlbum([pathUrl path], self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil); } to save video,but here is some error. My phone has 33.72GB available and the video is only 4.2GB in size. What should i do? ps: I try to use [PHPhotoLibrary sharedPhotoLibrary] performChanges to save, but i got the same error. error code -3305.
2
1
2.6k
Aug ’23
Reference photo from picker, rather than copy?
Hello, is it possible to reference a photo from the photo picker (either UIKit or SwiftUI), such that I do not need to copy it somewhere else? Currently, I am storing the copy in CoreData in a field with external storage, but it did cross my mind that I don't actually need a copy in my own storage if I could point back to the photo library. If the user deleted the photo from the library that would be fine.
1
0
395
Aug ’23
Is there a technical reason why Photos.app/PhotoKit does not support displaying file sizes?
It is 2023 and Photos.app still provides no way to sort photos/movies by file size. I ended up writing some AppleScript that displays the file sizes of images/movies in a specific album. It is also simple to create a shell script to examine the photo library contents directly but mapping the UUID-based filenames back to the names used in Photos.app is not straightforward (to me at least). You can't even create a smart album based upon file size. Why is there no native support for this in Photos.app/PhotoKit? (And, yes, I have submitted many feature requests over the years)
0
0
387
Aug ’23
PHAsset unique identifier across devices.
I know that I can uniquely identify a PHAsset on a given device using localIdentifier but if that asset is synched (through iCloud, say) to another device, how to I uniquely identify that asset across multiple devices? My app allows users to store their images in the standard photo gallery, but I have no way of referring to them when they sync their app profile to another iOS device with my app installed.
2
0
736
Aug ’23
What are the available NSSortDescriptors for PHFetchOptions?
I'm working with Apple's sample code for PhotoBrowse. In the main view controller's viewDidLoad() method we have this code: let allPhotosOptions = PHFetchOptions() allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)] This code sorts the photos by "creationDate". How do I determine/find the other valid values for these sort descriptors? For example, what if I wanted to sort photos by their file size, last modified date, etc.? TIA!
2
0
425
Aug ’23
Proper way to import screen recordings with SwiftUI PhotosPicker?
Hello, I am building contact form that allows to attach screenshots and screen recordings. The PhotosPicker part is relatively straightforward but I am not sure how to properly import the selected items. The binding is of type [PhotosPickerItem] which requires (at least for my current implementation) to first know if the item is image or video. I have this not so pretty code to detect if the item is video: let isVideo = item.supportedContentTypes.first(where: { $0.conforms(to: .video) }) != nil || item.supportedContentTypes.contains(.mpeg4Movie) Which for screen recordings seems to work only because I ask about .mpeg4Movie and then I have this struct: struct ScreenRecording: Transferable { let url: URL static var transferRepresentation: some TransferRepresentation { FileRepresentation(contentType: .mpeg4Movie) { video in SentTransferredFile(video.url) } importing: { received in let copy = URL.temporaryDirectory.appending(path: "\(UUID().uuidString).mp4") try FileManager.default.copyItem(at: received.file, to: copy) return Self.init(url: copy) } } } Notice here I have just the .mpeg4Movie content type, I couldn't get it to work with more generic ones like movie and I am afraid this implementation could soon break if the screen recordings change video format/codec. And finally my logic to load the item: if isVideo { if let movie = try? await item.loadTransferable(type: ScreenRecording.self) { viewModel.addVideoAttachment(movie) } } else { if let data = try? await item.loadTransferable(type: Data.self) { if let uiImage = UIImage(data: data) { viewModel.addScreenshotAttachment(uiImage) } } } I would like to make this more "future proof" and less error prone - particularly the screen recordings part. I don't even need the UIImage since I am saving the attachments as files, I just need to know if the attachment is screenshot or video and get its URL. Thanks!
0
0
585
Aug ’23
HEIF10 representation doesn't contain alpha channel
When using the heif10Representation and writeHEIF10Representation APIs of CIContext, the resulting image doesn’t contain an alpha channel. When using the heifRepresentation and writeHEIFRepresentation APIs, the alpha channel is properly preserved, i.e., the resulting HEIC will contain a urn:mpeg:hevc:2015:auxid:1 auxiliary image. This image is missing when exporting as HEIF10. Is this a bug or is this intentional? If I understand the spec correctly, HEIF10 should be able to support alpha via auxiliary image (like HEIF8).
1
0
770
Jul ’23
Permissions when creating an album for an app and saving media
I am trying to create an album for an app in photo_kit and store images in it, is there any way to do this under the NSPhotoLibraryAddUsageDescription permission? At first glance, using NSPhotoLibraryAddUsageDescription seems to be the best choice for this app, since I will not be loading any images. However, there are two album operations that can only be done under NSPhotoLibraryUsageDescription. Creating an album Even though the creation of an album does not involve loading media, it is necessary to use NSPhotoLibraryUsageDescription to allow users to load media. This is a bit unconvincing. Saving images in the created album Before saving, you must check to see if the app has already created the album. You need to fetch the name as a key. This is where NSPhotLibraryUsageDescription is needed. I understand that the NSPhotLibraryUsageDescription is needed for fetching, but if iOS forbids the creation of albums with the same name and ignores attempts to create an album with an already existing name, this fetching will not be necessary. In summary, I just want to create an album for my app and store media in it, but in order to do so I need to get permission from the user to read into the photos, which goes against the idea that the permissions I request should be minimal and only what I need. If there is a way to do this under the NSPhotoLibraryAddUsageDescription permission I would like to know, I am new to Swift so sorry if I am wrong.
1
0
803
Jul ’23