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

CGImageCreate() returns nil.
CGFloat width = any value;  CGFloat height = any value; CGDataProviderRef dataProviderRef = dataProviderRef = CGDataProviderCreateWithData(NULL, data, width * height * 2, nil); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderMask | kCGImageAlphaNoneSkipLast; CGImageRef imageResult = CGImageCreate(width, height, 8, 16, width * 2, CGColorSpaceCreateDeviceGray(), bitmapInfo, dataProviderRef, NULL, 0, kCGRenderingIntentDefault); imageResult is nil. Please tell me an alternative method.
1
0
894
Feb ’23
The problem that different color tone of heif file on Ventura 13.2
Hi ! I'm testing my HEIF image files on Ventura 13.2 and I found something about different color-tone on Finder's Gallery. Shortly I explain it, Gallery in Finder app shows a HEIF image shows more brighter than Preview app. It did not happen on Ventura 13.1, just happen in 13.2. In order to explain more detail, I attached PPT file and image files. PPT: https://docs.google.com/presentation/d/1743G7KcSGChSFVvmCF0JR-EsBeXkJtLAGpmu6lkgMHU/edit?usp=share_link Image: https://drive.google.com/file/d/1ImfCEWuOhGOLpwsgc5KwRVFTCtVAiZtz/view?usp=share_link So, hopefully, I'm expecting you guys to check this problem and answer this post! Eventually, I hope you fix up this issue that I addressed in this post. Thanks. Seunghoon Baek.
1
0
743
Feb ’23
How to show file image selected from disk (no Assets)?
Hi, I'm a beginner in Swift and I'm stuck. I just want a simple app that displays the image of the selected file on disk (not Assets) in a rectangle above "Hello world!". Thanks for any help! struct ContentView: View { var body: some View { VStack { // Rectangle example rectangle() .frame(width: 300, height: 300, alignment: .topLeading) Text("Hello, World!") Button("Select File"){ let pathfile = fSelectFile() //"....../Data/Image1.jpg" let img = NSImage(byReferencingFile: pathfile) img!.draw(in: NSRect(x: 10, y: 10, width: 300, height: 300)) } } } }
0
0
653
Jan ’23
Can't write grayscale HEIC image file on iOS16.2 with CGImageDestinationCreateWithData
CGImageRef grayscaleImage;  { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();     CGContextRef bitmapCtx = CGBitmapContextCreate(bwbuffer, width, height, 8, width, colorSpace, (CGBitmapInfo)kCGImageAlphaNone);     grayscaleImage = CGBitmapContextCreateImage(bitmapCtx);     CFRelease(bitmapCtx);     CFRelease(colorSpace);   } UIImage *temp = [[UIImage alloc] initWithCGImage:grayscaleImage]; CFStringRef UTI= (CFStringRef)@"public.heic"; NSMutableData *newImageData = [NSMutableData data]; CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)newImageData,UTI,1,NULL); CGImageDestinationAddImage(destination, temp.CGImage, (__bridge CFDictionaryRef)metaDataDictNew); CGImageDestinationFinalize(destination); This code running on iOS15. However iOS16 can't write grayscale HEIC image file.RGB image file is OK. The following were error message on console of xcode. writeImageAtIndex:867: *** CMPhotoCompressionSessionAddImage: err = kCMPhotoError_InvalidData [-17102]  (codec: 'hvc1') I can't find this error code in the Apple Support site also Documentation. Best regards.
0
0
1.2k
Jan ’23
what you see is what you get in AVCaptureVideoPreviewLayer
I created AVCaptureVideoPreviewLayer to get the video stream, videoGravity = AVLayerVideoGravityResizeAspectFill. But in the method - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection returns. I found that the actual conversion into UIImage is not what the user sees in AVCaptureVideoPreviewLayer, it is much more than what the user sees in AVCaptureVideoPreviewLayer, how can I get the sampleBuffer that the user sees in AVCaptureVideoPreviewLayer
0
0
1.1k
Dec ’22
iOS Camera is missing metadata when taking a Live Photo
Good morning everyone. I am having a problem with iOS devices when it comes to retrieving metadata from a photo (JPEG or HEIC). Indeed we have a widget on which we have an input type=image/* field that allows us either to upload a photo from the gallery or take a live shot to add the photo and thus extract the EXIF metadata (DateTimeOriginal, GPSLatitude and GPSLongitude). In the case where the user uploads the photo from his gallery, we manage to extract all this metadata but when the user takes a live shot, none of this metadata is present in the photo. On android, we do not encounter this problem. Can you dear community give me a solution to this problem? We have no solution to this blockage. I also saw on the forum a user who is facing the same problem: https://developer.apple.com/forums/thread/698573 Thank you all for your participation.
0
0
1k
Dec ’22
Advice about adding GPS location to in-app captured image
Firstly, hi everyone. Is a pleasure to ask the first question in this forum for me. I have a very uncommon (at least, that is what appears to be) case in our app. We have built a system that allows the end user to capture multiple images in-app and we send them to our servers. Actually, we need these arrays of images to be stored safely in the users' device, and I have thought about Core Data or FileManager for that purpose. I want to know which is the best way to make this happen (as more difficult is to edit the image, better). My question is: I have been able to add the GPS information to a PHAssetCreationRequest, and save that to the Gallery of the phone, but I am not able to save that information to the FileManager. How should I add the GPS data?
2
1
1.1k
Dec ’22
How do I invert the luminosity of the display using a color matrix or something else?
I recently came across a program that used data tables to invert the display, however it was a windows only application and I am wondering how I can write a similar thing for Mac, or if there is one already available. The app and config file is attached below so you can sort of dissect how it works Config File: [negativescreen.conf](https://developer.apple.com/forums/content/attachment/f4b67ed7-fa71-4ee6-9c0d-18febe2c3381) Readme file: [README.md](https://developer.apple.com/forums/content/attachment/86bd72f6-46c9-42d5-a925-561f75f24ae8) Window$ Executable: [NegativeScreen.exe](https://developer.apple.com/forums/content/attachment/a4478bd5-d5c7-41dd-9302-0e1a929372c2)
0
0
1.9k
Dec ’22
Object does not respond to selector
I'm trying to add functionality to save a picture from a URL to the user's photo library. here's the code: import Foundation import UIKit class ImageDownloader: NSObject { static func writeToPhotoAlbum(imageUrl: String) { let imageURL = URL(string: imageUrl)! if let image = try? Data(contentsOf: imageURL) { UIImageWriteToSavedPhotosAlbum(UIImage(data: image)!, self, nil, nil) } } @objc func saveCompleted( _ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { print("Save finished!") } } When i call the method like this: ImageDownloader.writeToPhotoAlbum(imageUrl: "image_url") I get this error: ImageDownloader does not respond to selector Any explanation and solution?
1
0
1.3k
Dec ’22
Save ARFrame capturedImage with camera EXIF data
According to the document, exifData is now provided for IOS 16 in ARFrame object. I'm saving the capturedImage in this way right now. How can I store the image with the corresponding exif data? let ciImageColor = CIImage(cvPixelBuffer: frame.capturedImage) let contextColor = CIContext.init(options: nil) let cgImageColor = contextColor.createCGImage(ciImageColor, from: ciImageColor.extent)! let uiImageColor = UIImage(cgImage: cgImageColor, scale: 1, orientation: UIImage.Orientation.up) uiImageColor.jpegData(compressionQuality: 0.0)!.write(to: colorJpgURL)
1
0
1.4k
Nov ’22
How to get thumbnail / preview image for items imported from PHPicker?
I am starting to use NSItemProvider methods hasRepresentationConforming and loadFileRepresentation for importing images, live photos and videos from PHPicker on iOS. I would like to generate thumbnails / preview images for each imported image, live photo and video. I tried using theNSItemProvider method loadPreviewImage, but in testing with Xcode Version 12.0 (12A7209) in iOS 14 Simulator, the NSItemProvider.CompletionHandler always returns nil for the item regardless of whether I use NSData, NSURL or UIImage. Is it best to generate thumbnails by scaling down imported images with UIGraphicsBeginImageContext and use AVAssetImageGenerator on imported videos?
3
2
3.9k
Nov ’22
Show Only Selected Image on PHPicker
Hello guys I wonder how to show your selected image on PHPicker. The privacy already on selected image bur the gallery show all image. Here's some code. Code on the view: import SwiftUI import PhotosUI struct ContentView: View {          @State var isPickerShowing = false     @State var selectedImage: UIImage?          var body: some View {         VStack {                          if selectedImage != nil {                 Image(uiImage: selectedImage!).resizable().frame(width: 200, height: 200)             }                          Button {                 checkPermission()             } label: {                 Text("select Photo")             }         }         .sheet(isPresented: $isPickerShowing, onDismiss: nil) {             //Image Picker             ImagePicker(imageToImport: $selectedImage, isPresented: $isPickerShowing)         }              }          func checkPermission() {                 let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()        switch photoAuthorizationStatus {        case .authorized:            print("Access is granted by user")            isPickerShowing = true        case .notDetermined:            PHPhotoLibrary.requestAuthorization({                (newStatus) in                print("status is \(newStatus)")                if newStatus ==  PHAuthorizationStatus.authorized {                    /* do stuff here */                    isPickerShowing = true                }            })            print("It is not determined until now")        case .restricted:            // same same            print("User do not have access to photo album.")        case .denied:            // same same            print("User has denied the permission.")        case .limited:            print("User Limited Show Photo.")        @unknown default:            print("User Unknow")        }             }      } Code on ImagePicker: import Foundation import PhotosUI import SwiftUI struct ImagePicker: UIViewControllerRepresentable {          @Binding var imageToImport: UIImage?     @Binding var isPresented: Bool          func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> some UIViewController {                  var configuration = PHPickerConfiguration()         configuration.filter = .images         configuration.selectionLimit = 1                  let imagePicker = PHPickerViewController(configuration: configuration)         imagePicker.delegate = context.coordinator         return imagePicker     }          func updateUIViewController(_ uiViewController: ImagePicker.UIViewControllerType, context: UIViewControllerRepresentableContext<ImagePicker>) {}          func makeCoordinator() -> ImagePicker.Coordinator {         return Coordinator(parent: self)     }          class Coordinator: NSObject, PHPickerViewControllerDelegate {                  var parent: ImagePicker                  init(parent: ImagePicker) {             self.parent = parent         }                  func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {                          picker.dismiss(animated: true)                          if results.count != 1 {                 return             }                          if let image = results.first {                                  if image.itemProvider.canLoadObject(ofClass: UIImage.self) {                     image.itemProvider.loadObject(ofClass: UIImage.self) { image, error  in                                                  if let image = image {                             self.parent.imageToImport = image as? UIImage                         }                     }                 }             }                          self.parent.isPresented.toggle()         }     } } Hope u guys can help me, I already search for these question for 2 weeks. Have a nice day :)
0
0
1.5k
Nov ’22
Extracting pixels with depth less than 3 meters from captured CVPixelBuffer type
Hello - I'm new to Swift and SwiftUI and was trying to capture a video or image from the LiDAR sensor. I've looked at the examples provided by Apple and made a simple app that draws color to objects depending on the pixel's depth. Red being close, blue being the furthest. However, now I want to perform some filtering on the captured data buffer, a type of CVPixelBuffer - I'm not sure how to extract pixels with a depth less than 3, for example, or 0.3, after normalizing the pixels. My goal is to have something similar to the code below:         var depthDataMap = syncedDepthData.depthData         if syncedDepthData.depthData.depthDataType != kCVPixelFormatType_DisparityFloat32 {                     depthDataMap = syncedDepthData.depthData.converting(toDepthDataType: kCVPixelFormatType_DisparityFloat32)                 }         depthDataMap.depthDataMap.normalize() # after getting the depth map how can I extract all the pixels or indexes with depth less than some number depthDataMap.depthDataMap.filter(depth=3) # result I'm looking for all the pixels with depth less than 3 I'm sure there is a way to call this method from the CPU. Thanks for any help or information. Matt
0
0
834
Nov ’22
"GPS Img Direction" not updating on Burst photos
Hi! I do not know if it is a bug but I have captured 52 photos on burst mode while rotating on a 360 circle to create a manual panorama and seen that "GPS Img Direction" not updating. However, File Name File Size File Modification Date/Time File Access Date/Time File Creation Date/Time Modify Date Exposure Time Date/Time Original Create Date Shutter Speed Value Brightness Value Run Time Value Acceleration Vector Sub Sec Time Original Sub Sec Time Digitized Thumbnail Length Run Time Since Power Up Shutter Speed Create Date Date/Time Original Modify Date Thumbnail Image Light Value are updating on each photo exif file. other not updated sections that might be relevant; GPS Latitude Ref GPS Latitude GPS Longitude Ref GPS Longitude GPS Altitude Ref GPS Altitude GPS Speed Ref GPS Speed GPS Img Direction Ref GPS Img Direction GPS Dest Bearing Ref GPS Dest Bearing GPS Date Stamp GPS Horizontal Positioning Error Connection Space Illuminant Media White Point Red Matrix Column Green Matrix Column Blue Matrix Column
0
0
1.1k
Nov ’22
Old macOS duplicate detection in Photos
A few of our users reported that images saved with our apps disappear from their library in Photos after a few seconds. All of them own a Mac with an old version of macOS, and all of them have iCloud syncing enabled for Photos. Our apps use Core Image to process images. Core Image will transfer most of the input's metadata to the output. While we thought this was generally a good idea, this seems to be causing the issue: The old version of Photos (or even iPhoto?) that is running on the Mac seems to think that the output image of our app is a duplicate of the original image that was loaded into our app. As soon as the iCloud sync happens, the Mac removes the image from the library, even when it's in sleep mode. When the Mac is turned off or disconnected from the internet, the images stay in the library—until the Mac comes back online. This seems to be caused by the output's metadata, but we couldn't figure out what fields are causing the old Photos to detect the new image as duplicate. It's also very hard to reproduce without installing an old macOS on some machine. Does anyone know what metadata field we need to change to not be considered a duplicate?
0
0
1.1k
Oct ’22
CIContext::heifRepresentation randomly crashing in iOS 16
The following call to heifRepresentation is causing occasional crashes in iOS 16. context.heifRepresentation(of: image, format: CIFormat.RGBA8, colorSpace: perceptualColorSpace!, options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption : 0.6] ) When we switch to context.jpegRepresentation: return context.jpegRepresentation(of: image, colorSpace: perceptualColorSpace!, options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption : compressionFactor]) The app runs fine. Also, the context.heifRepresentation runs fine on iOS 15. Can someone please help?
0
1
881
Oct ’22
CGImageCreate() returns nil.
CGFloat width = any value;  CGFloat height = any value; CGDataProviderRef dataProviderRef = dataProviderRef = CGDataProviderCreateWithData(NULL, data, width * height * 2, nil); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderMask | kCGImageAlphaNoneSkipLast; CGImageRef imageResult = CGImageCreate(width, height, 8, 16, width * 2, CGColorSpaceCreateDeviceGray(), bitmapInfo, dataProviderRef, NULL, 0, kCGRenderingIntentDefault); imageResult is nil. Please tell me an alternative method.
Replies
1
Boosts
0
Views
894
Activity
Feb ’23
The problem that different color tone of heif file on Ventura 13.2
Hi ! I'm testing my HEIF image files on Ventura 13.2 and I found something about different color-tone on Finder's Gallery. Shortly I explain it, Gallery in Finder app shows a HEIF image shows more brighter than Preview app. It did not happen on Ventura 13.1, just happen in 13.2. In order to explain more detail, I attached PPT file and image files. PPT: https://docs.google.com/presentation/d/1743G7KcSGChSFVvmCF0JR-EsBeXkJtLAGpmu6lkgMHU/edit?usp=share_link Image: https://drive.google.com/file/d/1ImfCEWuOhGOLpwsgc5KwRVFTCtVAiZtz/view?usp=share_link So, hopefully, I'm expecting you guys to check this problem and answer this post! Eventually, I hope you fix up this issue that I addressed in this post. Thanks. Seunghoon Baek.
Replies
1
Boosts
0
Views
743
Activity
Feb ’23
How to show file image selected from disk (no Assets)?
Hi, I'm a beginner in Swift and I'm stuck. I just want a simple app that displays the image of the selected file on disk (not Assets) in a rectangle above "Hello world!". Thanks for any help! struct ContentView: View { var body: some View { VStack { // Rectangle example rectangle() .frame(width: 300, height: 300, alignment: .topLeading) Text("Hello, World!") Button("Select File"){ let pathfile = fSelectFile() //"....../Data/Image1.jpg" let img = NSImage(byReferencingFile: pathfile) img!.draw(in: NSRect(x: 10, y: 10, width: 300, height: 300)) } } } }
Replies
0
Boosts
0
Views
653
Activity
Jan ’23
Can't write grayscale HEIC image file on iOS16.2 with CGImageDestinationCreateWithData
CGImageRef grayscaleImage;  { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();     CGContextRef bitmapCtx = CGBitmapContextCreate(bwbuffer, width, height, 8, width, colorSpace, (CGBitmapInfo)kCGImageAlphaNone);     grayscaleImage = CGBitmapContextCreateImage(bitmapCtx);     CFRelease(bitmapCtx);     CFRelease(colorSpace);   } UIImage *temp = [[UIImage alloc] initWithCGImage:grayscaleImage]; CFStringRef UTI= (CFStringRef)@"public.heic"; NSMutableData *newImageData = [NSMutableData data]; CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)newImageData,UTI,1,NULL); CGImageDestinationAddImage(destination, temp.CGImage, (__bridge CFDictionaryRef)metaDataDictNew); CGImageDestinationFinalize(destination); This code running on iOS15. However iOS16 can't write grayscale HEIC image file.RGB image file is OK. The following were error message on console of xcode. writeImageAtIndex:867: *** CMPhotoCompressionSessionAddImage: err = kCMPhotoError_InvalidData [-17102]  (codec: 'hvc1') I can't find this error code in the Apple Support site also Documentation. Best regards.
Replies
0
Boosts
0
Views
1.2k
Activity
Jan ’23
JPEG compression for TIFF no longer supported
hello! Came across with subj in https://developer.apple.com/documentation/appkit/nstiffcompression?language=objc Why? And what is the right (Apple) way to archive this?
Replies
0
Boosts
0
Views
672
Activity
Jan ’23
what you see is what you get in AVCaptureVideoPreviewLayer
I created AVCaptureVideoPreviewLayer to get the video stream, videoGravity = AVLayerVideoGravityResizeAspectFill. But in the method - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection returns. I found that the actual conversion into UIImage is not what the user sees in AVCaptureVideoPreviewLayer, it is much more than what the user sees in AVCaptureVideoPreviewLayer, how can I get the sampleBuffer that the user sees in AVCaptureVideoPreviewLayer
Replies
0
Boosts
0
Views
1.1k
Activity
Dec ’22
iOS Camera is missing metadata when taking a Live Photo
Good morning everyone. I am having a problem with iOS devices when it comes to retrieving metadata from a photo (JPEG or HEIC). Indeed we have a widget on which we have an input type=image/* field that allows us either to upload a photo from the gallery or take a live shot to add the photo and thus extract the EXIF metadata (DateTimeOriginal, GPSLatitude and GPSLongitude). In the case where the user uploads the photo from his gallery, we manage to extract all this metadata but when the user takes a live shot, none of this metadata is present in the photo. On android, we do not encounter this problem. Can you dear community give me a solution to this problem? We have no solution to this blockage. I also saw on the forum a user who is facing the same problem: https://developer.apple.com/forums/thread/698573 Thank you all for your participation.
Replies
0
Boosts
0
Views
1k
Activity
Dec ’22
Advice about adding GPS location to in-app captured image
Firstly, hi everyone. Is a pleasure to ask the first question in this forum for me. I have a very uncommon (at least, that is what appears to be) case in our app. We have built a system that allows the end user to capture multiple images in-app and we send them to our servers. Actually, we need these arrays of images to be stored safely in the users' device, and I have thought about Core Data or FileManager for that purpose. I want to know which is the best way to make this happen (as more difficult is to edit the image, better). My question is: I have been able to add the GPS information to a PHAssetCreationRequest, and save that to the Gallery of the phone, but I am not able to save that information to the FileManager. How should I add the GPS data?
Replies
2
Boosts
1
Views
1.1k
Activity
Dec ’22
How do I invert the luminosity of the display using a color matrix or something else?
I recently came across a program that used data tables to invert the display, however it was a windows only application and I am wondering how I can write a similar thing for Mac, or if there is one already available. The app and config file is attached below so you can sort of dissect how it works Config File: [negativescreen.conf](https://developer.apple.com/forums/content/attachment/f4b67ed7-fa71-4ee6-9c0d-18febe2c3381) Readme file: [README.md](https://developer.apple.com/forums/content/attachment/86bd72f6-46c9-42d5-a925-561f75f24ae8) Window$ Executable: [NegativeScreen.exe](https://developer.apple.com/forums/content/attachment/a4478bd5-d5c7-41dd-9302-0e1a929372c2)
Replies
0
Boosts
0
Views
1.9k
Activity
Dec ’22
Object does not respond to selector
I'm trying to add functionality to save a picture from a URL to the user's photo library. here's the code: import Foundation import UIKit class ImageDownloader: NSObject { static func writeToPhotoAlbum(imageUrl: String) { let imageURL = URL(string: imageUrl)! if let image = try? Data(contentsOf: imageURL) { UIImageWriteToSavedPhotosAlbum(UIImage(data: image)!, self, nil, nil) } } @objc func saveCompleted( _ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { print("Save finished!") } } When i call the method like this: ImageDownloader.writeToPhotoAlbum(imageUrl: "image_url") I get this error: ImageDownloader does not respond to selector Any explanation and solution?
Replies
1
Boosts
0
Views
1.3k
Activity
Dec ’22
Save ARFrame capturedImage with camera EXIF data
According to the document, exifData is now provided for IOS 16 in ARFrame object. I'm saving the capturedImage in this way right now. How can I store the image with the corresponding exif data? let ciImageColor = CIImage(cvPixelBuffer: frame.capturedImage) let contextColor = CIContext.init(options: nil) let cgImageColor = contextColor.createCGImage(ciImageColor, from: ciImageColor.extent)! let uiImageColor = UIImage(cgImage: cgImageColor, scale: 1, orientation: UIImage.Orientation.up) uiImageColor.jpegData(compressionQuality: 0.0)!.write(to: colorJpgURL)
Replies
1
Boosts
0
Views
1.4k
Activity
Nov ’22
How to get thumbnail / preview image for items imported from PHPicker?
I am starting to use NSItemProvider methods hasRepresentationConforming and loadFileRepresentation for importing images, live photos and videos from PHPicker on iOS. I would like to generate thumbnails / preview images for each imported image, live photo and video. I tried using theNSItemProvider method loadPreviewImage, but in testing with Xcode Version 12.0 (12A7209) in iOS 14 Simulator, the NSItemProvider.CompletionHandler always returns nil for the item regardless of whether I use NSData, NSURL or UIImage. Is it best to generate thumbnails by scaling down imported images with UIGraphicsBeginImageContext and use AVAssetImageGenerator on imported videos?
Replies
3
Boosts
2
Views
3.9k
Activity
Nov ’22
Show Only Selected Image on PHPicker
Hello guys I wonder how to show your selected image on PHPicker. The privacy already on selected image bur the gallery show all image. Here's some code. Code on the view: import SwiftUI import PhotosUI struct ContentView: View {          @State var isPickerShowing = false     @State var selectedImage: UIImage?          var body: some View {         VStack {                          if selectedImage != nil {                 Image(uiImage: selectedImage!).resizable().frame(width: 200, height: 200)             }                          Button {                 checkPermission()             } label: {                 Text("select Photo")             }         }         .sheet(isPresented: $isPickerShowing, onDismiss: nil) {             //Image Picker             ImagePicker(imageToImport: $selectedImage, isPresented: $isPickerShowing)         }              }          func checkPermission() {                 let photoAuthorizationStatus = PHPhotoLibrary.authorizationStatus()        switch photoAuthorizationStatus {        case .authorized:            print("Access is granted by user")            isPickerShowing = true        case .notDetermined:            PHPhotoLibrary.requestAuthorization({                (newStatus) in                print("status is \(newStatus)")                if newStatus ==  PHAuthorizationStatus.authorized {                    /* do stuff here */                    isPickerShowing = true                }            })            print("It is not determined until now")        case .restricted:            // same same            print("User do not have access to photo album.")        case .denied:            // same same            print("User has denied the permission.")        case .limited:            print("User Limited Show Photo.")        @unknown default:            print("User Unknow")        }             }      } Code on ImagePicker: import Foundation import PhotosUI import SwiftUI struct ImagePicker: UIViewControllerRepresentable {          @Binding var imageToImport: UIImage?     @Binding var isPresented: Bool          func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> some UIViewController {                  var configuration = PHPickerConfiguration()         configuration.filter = .images         configuration.selectionLimit = 1                  let imagePicker = PHPickerViewController(configuration: configuration)         imagePicker.delegate = context.coordinator         return imagePicker     }          func updateUIViewController(_ uiViewController: ImagePicker.UIViewControllerType, context: UIViewControllerRepresentableContext<ImagePicker>) {}          func makeCoordinator() -> ImagePicker.Coordinator {         return Coordinator(parent: self)     }          class Coordinator: NSObject, PHPickerViewControllerDelegate {                  var parent: ImagePicker                  init(parent: ImagePicker) {             self.parent = parent         }                  func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {                          picker.dismiss(animated: true)                          if results.count != 1 {                 return             }                          if let image = results.first {                                  if image.itemProvider.canLoadObject(ofClass: UIImage.self) {                     image.itemProvider.loadObject(ofClass: UIImage.self) { image, error  in                                                  if let image = image {                             self.parent.imageToImport = image as? UIImage                         }                     }                 }             }                          self.parent.isPresented.toggle()         }     } } Hope u guys can help me, I already search for these question for 2 weeks. Have a nice day :)
Replies
0
Boosts
0
Views
1.5k
Activity
Nov ’22
Extracting pixels with depth less than 3 meters from captured CVPixelBuffer type
Hello - I'm new to Swift and SwiftUI and was trying to capture a video or image from the LiDAR sensor. I've looked at the examples provided by Apple and made a simple app that draws color to objects depending on the pixel's depth. Red being close, blue being the furthest. However, now I want to perform some filtering on the captured data buffer, a type of CVPixelBuffer - I'm not sure how to extract pixels with a depth less than 3, for example, or 0.3, after normalizing the pixels. My goal is to have something similar to the code below:         var depthDataMap = syncedDepthData.depthData         if syncedDepthData.depthData.depthDataType != kCVPixelFormatType_DisparityFloat32 {                     depthDataMap = syncedDepthData.depthData.converting(toDepthDataType: kCVPixelFormatType_DisparityFloat32)                 }         depthDataMap.depthDataMap.normalize() # after getting the depth map how can I extract all the pixels or indexes with depth less than some number depthDataMap.depthDataMap.filter(depth=3) # result I'm looking for all the pixels with depth less than 3 I'm sure there is a way to call this method from the CPU. Thanks for any help or information. Matt
Replies
0
Boosts
0
Views
834
Activity
Nov ’22
"GPS Img Direction" not updating on Burst photos
Hi! I do not know if it is a bug but I have captured 52 photos on burst mode while rotating on a 360 circle to create a manual panorama and seen that "GPS Img Direction" not updating. However, File Name File Size File Modification Date/Time File Access Date/Time File Creation Date/Time Modify Date Exposure Time Date/Time Original Create Date Shutter Speed Value Brightness Value Run Time Value Acceleration Vector Sub Sec Time Original Sub Sec Time Digitized Thumbnail Length Run Time Since Power Up Shutter Speed Create Date Date/Time Original Modify Date Thumbnail Image Light Value are updating on each photo exif file. other not updated sections that might be relevant; GPS Latitude Ref GPS Latitude GPS Longitude Ref GPS Longitude GPS Altitude Ref GPS Altitude GPS Speed Ref GPS Speed GPS Img Direction Ref GPS Img Direction GPS Dest Bearing Ref GPS Dest Bearing GPS Date Stamp GPS Horizontal Positioning Error Connection Space Illuminant Media White Point Red Matrix Column Green Matrix Column Blue Matrix Column
Replies
0
Boosts
0
Views
1.1k
Activity
Nov ’22
Is there a way encode/decode portion of a huge Image?
if there is a huge image(10000x10000), loading it into memory will cause crash every time. so, can I load a portion of image into memory and process it, and write back this part to image file?
Replies
0
Boosts
0
Views
1.3k
Activity
Oct ’22
can approval
we are communication platform with encrypted messeges we love to to be on apple purekonect
Replies
0
Boosts
0
Views
1.7k
Activity
Oct ’22
Old macOS duplicate detection in Photos
A few of our users reported that images saved with our apps disappear from their library in Photos after a few seconds. All of them own a Mac with an old version of macOS, and all of them have iCloud syncing enabled for Photos. Our apps use Core Image to process images. Core Image will transfer most of the input's metadata to the output. While we thought this was generally a good idea, this seems to be causing the issue: The old version of Photos (or even iPhoto?) that is running on the Mac seems to think that the output image of our app is a duplicate of the original image that was loaded into our app. As soon as the iCloud sync happens, the Mac removes the image from the library, even when it's in sleep mode. When the Mac is turned off or disconnected from the internet, the images stay in the library—until the Mac comes back online. This seems to be caused by the output's metadata, but we couldn't figure out what fields are causing the old Photos to detect the new image as duplicate. It's also very hard to reproduce without installing an old macOS on some machine. Does anyone know what metadata field we need to change to not be considered a duplicate?
Replies
0
Boosts
0
Views
1.1k
Activity
Oct ’22
CIContext::heifRepresentation randomly crashing in iOS 16
The following call to heifRepresentation is causing occasional crashes in iOS 16. context.heifRepresentation(of: image, format: CIFormat.RGBA8, colorSpace: perceptualColorSpace!, options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption : 0.6] ) When we switch to context.jpegRepresentation: return context.jpegRepresentation(of: image, colorSpace: perceptualColorSpace!, options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption : compressionFactor]) The app runs fine. Also, the context.heifRepresentation runs fine on iOS 15. Can someone please help?
Replies
0
Boosts
1
Views
881
Activity
Oct ’22
Change the resolution of the images
Hello, I have the problem that I have an image slider user and this makes the RAM consumption very high. Is there a way that the images are automatically scaled down to still look sharp on the device in question? I don't want to scale down every single image myself and am looking at a way a code would automatically make that fit for me. Thanks a lot!
Replies
0
Boosts
0
Views
1k
Activity
Sep ’22