Image I/O

RSS for tag

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

Image I/O Documentation

Posts under Image I/O tag

64 Posts
Sort by:
Post not yet marked as solved
1 Replies
1.6k Views
We are using PNG Transparent logo image for display in Dark and Light theme when sending a mail to the user. So, based on the user's screen settings, i.e. dark or light theme, background of the logo will be Black for Dark theme and White for Light theme.   But this is not working in the case of Yahoo mail app for iPhone dark theme. Yahoo mail app in iPhone for dark theme, by default, renders a white background color on CIBC logo image which is not looking good. Request you to kindly advise on the above. Please find screenshot of the issue attached.
Posted
by
Post not yet marked as solved
3 Replies
1.8k Views
I  am trying to save an image to the user's photo library using PHPhotoLibrary and set the image file name at the time of saving suing the code below. This is working the first time, but if I then try to save the same image again with a different file name, it saves with the same file name as before. Is there something I need to add to let the system know to save a new version of the image with a new file name? Thank you PHPhotoLibrary.shared().performChanges ({ let assetType:PHAssetResourceType = .photo let request:PHAssetCreationRequest = .forAsset() let createOptions:PHAssetResourceCreationOptions = PHAssetResourceCreationOptions() createOptions.originalFilename = "\(fileName)" request.addResource(with: assetType, data: image.jpegData(compressionQuality: 1)!, options: createOptions) }, completionHandler: { success, error in if success == true && error == nil { print("Success saving image") } else { print("Error saving image: \(error!.localizedDescription)") } })
Posted
by
Post not yet marked as solved
0 Replies
1.2k Views
I'm using CoreGraphics and Image I/O in a MacOS command-line tool. My program works fine, but after the first drawing to a bitmap context there are messages output to the console like the following: 2022-12-20 16:33:47.824937-0500 RandomImageGenerator[4436:90170] Metal API Validation Enabled AVEBridge Info: AVEEncoder_CreateInstance: Received CreateInstance (from VT) AVEBridge Info: connectHandler: Device connected (0x000000010030b520)Assert - (remoteService != NULL) - f: /AppleInternal/Library/BuildRoots/43362d89-619c-11ed-a949-7ef33c48bc85/Library/Caches/com.apple.xbs/Sources/AppleAVEBridge/AppleAVEEncoder/AppleAVEEncoder.c l: 291 AVE XPC Error: could not find remote service Assert - (err == noErr) - f: /AppleInternal/Library/BuildRoots/43362d89-619c-11ed-a949-7ef33c48bc85/Library/Caches/com.apple.xbs/Sources/AppleAVEBridge/AppleAVEEncoder/AppleAVEEncoder.c l: 1961 AVE ERROR: XPC failed AVEBridge Info: stopUserClient: IOServiceClose was successful. AVEBridge Error: AVEEncoder_CreateInstance: returning err = -12908 These messages get in the way of my own console output. How do I stop these messages from being displayed? This post on StackOverflow (https://stackoverflow.com/questions/37800790/hide-strange-unwanted-xcode-logs) does not appear to be relevant to this issue.
Posted
by
Post not yet marked as solved
0 Replies
1.5k Views
In iOS 16, can not displaying PDF included gradients. PDF displayed normally if used Radial or Linear Gradient. Complex shape gradients are not displayed. The PDF is not displayed inside the iOS-application resources and when open file in iPhone use Files app normally. Attached an example with a regular Diamond gradient, which was created use Figma. iOS 15 displays the example file correctly. You can open file if change file format: Example.json rename to -> Example.pdf. P.S. I can't attached pdf or zip files. Example.json
Posted
by
Post not yet marked as solved
3 Replies
1.6k Views
I take a picture using the iPhone's camera. The taken resolution is 3024.0 x 4032. I then have to apply a watermark to this image. After a bunch of trial and error, the method I decided to use was taking a snapshot of a watermark UIView, and drawing that over the image, like so: // Create the watermarked photo. let result: UIImage=UIGraphicsImageRenderer(size: image.size).image(actions: { _ in   image.draw(in: .init(origin: .zero, size: image.size))   let watermark: Watermark = .init(     size: image.size,     scaleFactor: image.size.smallest / self.frame.size.smallest   )   watermark.drawHierarchy(in: .init(origin: .zero, size: image.size), afterScreenUpdates: true) }) Then with the final image — because the client wanted it to have a filename as well when viewed from within the Photos app and exported from it, and also with much trial and error — I save it to a file in a temporary directory. I then save it to the user's Photo library using that file. The difference as compared to saving the image directly vs saving it from the file is that when saved from the file the filename is used as the filename within the Photos app; and in the other case it's just a default photo name generated by Apple. The problem is that in the image saving code I'm getting the following error: [Metal] 9072 by 12096 iosurface is too large for GPU And when I view the saved photo it's basically just a completely black image. This problem only started when I changed the AVCaptureSession preset to .photo. Before then there was no errors. Now, the worst problem is that the app just completely crashes on drawing of the watermark view in the first place. When using .photo the resolution is significantly higher, so the image size is larger, so the watermark size has to be commensurately larger as well. iOS appears to be okay with the size of the watermark UIView. However, when I try to draw it over the image the app crashes with this message from Xcode: So there's that problem. But I figured that could be resolved by taking a more manual approach to the drawing of the watermark then using a UIView snapshot. So it's not the most pressing problem. What is, is that even after the drawing code is commented out, I still get the iosurface is too large error. Here's the code that saves the image to the file and then to the Photos library: extension UIImage {   /// Save us with the given name to the user's photo album.   /// - Parameters:   ///  - filename: The filename to be used for the saved photo. Behavior is undefined if the filename contain characters other than what is represented by this regular expression [A-Za-z0-9-_]. A decimal point for the file extension is permitted.   ///  - location: A GPS location to save with the photo.   fileprivate func save(_ filename: String, _ location: Optional<Coordinates>) throws {           // Create a path to a temporary directory. Adding filenames to the Photos app form of images is accomplished by first creating an image file on the file system, saving the photo using the URL to that file, and then deleting that file on the file system.     //   A documented way of adding filenames to photos saved to Photos was never found.     // Furthermore, we save everything to a `tmp` directory as if we just tried deleting individual photos after they were saved, and the deletion failed, it would be a little more tricky setting up logic to ensure that the undeleted files are eventually     // cleaned up. But by using a `tmp` directory, we can save all temporary photos to it, and delete the entire directory following each taken picture.     guard       let tmpUrl: URL=try {         guard let documentsDirUrl=NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first else {           throw GeneralError("Failed to create URL to documents directory.")         }         let url: Optional<URL> = .init(string: documentsDirUrl + "/tmp/")         return url       }()     else {       throw GeneralError("Failed to create URL to temporary directory.")     }           // A path to the image file.     let filePath: String=try {               // Reduce the likelihood of photos taken in quick succession from overwriting each other.       let collisionResistantPath: String="\(tmpUrl.path(percentEncoded: false))\(UUID())/"               // Make sure all directories required by the path exist before trying to write to it.       try FileManager.default.createDirectory(atPath: collisionResistantPath, withIntermediateDirectories: true, attributes: nil)               // Done.       return collisionResistantPath + filename     }()     // Create `CFURL` analogue of file path.     guard let cfPath: CFURL=CFURLCreateWithFileSystemPath(nil, filePath as CFString, CFURLPathStyle.cfurlposixPathStyle, false) else {       throw GeneralError("Failed to create `CFURL` analogue of file path.")     }           // Create image destination object.     //     // You can change your exif type here.     //   This is a note from original author. Not quite exactly sure what they mean by it. Link in method documentation can be used to refer back to the original context.     guard let destination=CGImageDestinationCreateWithURL(cfPath, UTType.jpeg.identifier as CFString, 1, nil) else {       throw GeneralError("Failed to create `CGImageDestination` from file url.")     }           // Metadata properties.     let properties: CFDictionary={               // Place your metadata here.       // Keep in mind that metadata follows a standard. You can not use custom property names here.       let tiffProperties: Dictionary<String, Any>=[:]               return [         kCGImagePropertyExifDictionary as String: tiffProperties       ] as CFDictionary     }()           // Create image file.     guard let cgImage=self.cgImage else {       throw GeneralError("Failed to retrieve `CGImage` analogue of `UIImage`.")     }     CGImageDestinationAddImage(destination, cgImage, properties)     CGImageDestinationFinalize(destination)             // Save to the photo library.     PHPhotoLibrary.shared().performChanges({       guard let creationRequest: PHAssetChangeRequest = .creationRequestForAssetFromImage(atFileURL: URL(fileURLWithPath: filePath)) else {         return       }       // Add metadata to the photo.       creationRequest.creationDate = .init()       if let location=location {         creationRequest.location = .init(latitude: location.latitude, longitude: location.longitude)       }     }, completionHandler: { _, _ in       try? FileManager.default.removeItem(atPath: tmpUrl.absoluteString)     })   } } If anyone can provide some insight as to what's causing the iosurface is too large error and what can be done to resolve it, that'd be awesome.
Posted
by
Post not yet marked as solved
1 Replies
1.9k Views
Hello! I'm unable to take pictures from my swiftui app using a simple image picker, the camera sheet comes up but when I take a picture and choose" use this picture", nothing happens, this is the error I keep getting: Attempted to change to mode Portrait with an unsupported device (BackAuto). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto). Please does anyone have any advice on how I can fix this
Posted
by
Post not yet marked as solved
1 Replies
1.2k Views
Environment Xcode 14 ios 16 Error [Unknown process name] CGImageCreate: invalid image byte order info for bitsPerPixel != 32 = 16384 And when I run my app in iphone, it can't show the image of result. It seems that there are some bugs when running in ios 16. How can I solve this problem?
Posted
by
Post not yet marked as solved
0 Replies
536 Views
Hi everyone, I'm currently working on an app that allows users in the US and Canada to generate social media captions for their images using AI. The app has a feature where users can save the generated captions, and I'm considering whether or not to store the associated images on Firebase storage. My main goal is to allow users to refer back to their images when they view their saved captions. However, I'm also concerned about potential legal issues that might arise from storing user-generated images, especially since the app is not designed for sharing these images with other users. To give users more control over their data, I'm thinking about adding a toggle in the settings menu that allows them to choose if their images should be stored or not. I believe this could improve transparency and user satisfaction, but I'm unsure if this approach would help me avoid legal issues related to data storage and privacy for US and Canadian users. I would appreciate any insights or suggestions from the community, especially if you have experience with similar features or legal concerns in the context of US and Canadian data protection regulations. Also, I'd be grateful for recommendations on where to seek more information or consult with professionals in this area. Thanks in advance for your help!
Posted
by
Post not yet marked as solved
0 Replies
533 Views
I have a csv file with values ranges between 0-1. When converted this csv values to MLMultiArray and then to UIImage it shows grey image. But the image is actually coloured. So is there any step missing or do I have to perform any more action to get this image to be coloured. Sample csv values - [0.556862745 0.62745098 0.811764706]
Posted
by
Post marked as solved
2 Replies
518 Views
Excuse me, it may be a fool question. But how to load an image, access to its pixels and save it to disk. I used to programming in C++ via OpenCV. And I'm a new player in swift. Thanks!
Posted
by
Post not yet marked as solved
0 Replies
535 Views
Example : android url : https://play.google.com/store/apps/details?id=com.moevd.android.user&referrer=t=u&c=Azhar Android getting this referrer from play store by google Analytics . how this possible for iOS ? like how can we get referrer from App Store ? how related google analytics to Apple Store? info given above.
Posted
by
Post not yet marked as solved
0 Replies
595 Views
ImageSaver class: class ImageSaver: NSObject { var successHandler: (() -> Void)? var errorHandler: ((Error) -> Void)? func writeToPhotoAlbum(image: UIImage) { UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveCompleted), nil) } @objc func saveCompleted(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { if let error = error { errorHandler?(error) } else { successHandler?() } } } button action to trigger the download of a png file from URL: Button{ let imageSaver = ImageSaver() imageSaver.successHandler = { print("Success!") } imageSaver.errorHandler = { print("Oops: \($0.localizedDescription)") } let imageRequestUrl = URL(string: lastImageUrl)! // I'm sure that I can see the image url is valid and I can // downloaded it from Google chrome successfully print("imageRequestUrl:\(imageRequestUrl)") let req = URLRequest(url: imageRequestUrl) let task = URLSession.shared.dataTask(with: req) { d, res, err in if let data = d, let image = UIImage(data: data) { imageSaver.writeToPhotoAlbum(image: image) } } task.resume() } And this is the error: findWriterForTypeAndAlternateType:119: unsupported file format 'org.webmproject.webp' More info When I change the image URL to another one, like some other open-source png file, there's no error.... please help why it's so weird?
Posted
by
Post not yet marked as solved
1 Replies
572 Views
I was trying to take an image of a car that includes the license plate. But later when I checked the numbers in the license plate is not clear and readable. When I did a zoom there are slanting lines in place. Is there any settings available to avoid?
Posted
by
Post not yet marked as solved
2 Replies
695 Views
Hi all, I got an error: 'Color' cannot be constructed because it has no accessible initializers. The error I get from the statement: .background(Color(uiColor: UIColor(red: 0.93, green: 0.93, blue: 0.94, alpha: 1.00))) I always use it but it's failed now. Is there anyone have the same issues? Please give me an advice of how I can fix it. Thanks
Posted
by
Post not yet marked as solved
0 Replies
750 Views
Hi, I have some SVG assets that are natively in 512x512 resolution. I want to use 20 of them in a Widget context where memory consumption must be kept low (due to 30MB Memory limit in extensions). As in that widget context, the images are display in small size (they are displayed in full size in the app) I would like to load a downsampled version of the images (let say 32x32). Is there any way to achieve that? (perhaps with configuration or traitCollection) I could resize them after having loading them full size but it will nevertheless create a memory peak consumption while resizing all the images... Thanks in advance for the help. PS: I really want to avoid to generate smaller preview images just for that purpose but if I can't find a better solution I could ask the app to generate thumbs for all images at first startup and use these thumbs in the widgets... Clement
Posted
by
Post not yet marked as solved
0 Replies
679 Views
I am getting 4 warnings compiling the current template of sceneKit game /Users/helmut/Documents/spaceTime/scntool:1:1 Could not find bundle inside /Library/Developer/CommandLineTools any idea why the bundle is not installed I did a new download twice now still stuck getting these warnings about bundles not installed or not found any solution to correct the download install so the base dependencies are present thank you
Posted
by
Post not yet marked as solved
0 Replies
709 Views
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).
Posted
by
Post not yet marked as solved
0 Replies
765 Views
Previously art work used and porting a complex 3D mechanical Clock I am running into constant build errors using my previous art work .scn files I had some success converting my .usdz original to .scn file some convert but most just being in the art folder of the build environment cause this crash and are no longer compatible I use the same art work of gears and parts in UNITY build environment without any build issues most of my clocks have up to 35 different interacting parts These are replicas of classical clock mechanism Is any one else having problems with similar .scn files [?]
Posted
by
Post not yet marked as solved
9 Replies
1.8k Views
I was wondering if anyone has same problem. When i plug the iphone to my windows laptop the folders in iphone showing a chinese word next to the folder name. Also images format having different type of word and when i copy them to the windows, it doesn't recognize them as images. I have already erase the iphone and when plug again, same issue is there. Please refer attached two pics. I'm running IOS 17 public beta.
Posted
by
Post not yet marked as solved
1 Replies
1.1k Views
Hello everyone, I'm facing an issue with my SwiftUI project, and I would appreciate some help in resolving it. The problem is that one of the images in my project is not visible when I use it in my code. Here are the details of the issue: I have for example two images, "AIOx2.png" and "AIOx3.png", both of which are placed in the "Assets.xcassets" folder of my Xcode project. When I use "AIOx3.png" in my SwiftUI code (e.g., replacing Image("AIOx2") with Image("AIOx3")), the image is visible on the preview canvas and simulator. However, when I use "AIOx2.png" in the same way, the image is not visible on the preview canvas or the simulator. I have verified that the file "AIOx2.png" is correctly named and is in the same location as "AIOx3.png" in the "Assets.xcassets" folder. There are no error messages or warnings related to the image in the Xcode console. I have tried several troubleshooting steps, such as cleaning and build, restarting Xcode, re-downloading and re-adding the image to the project, but the issue persists. Is there anything specific that I might be missing or any other suggestions for troubleshooting this problem? I would be grateful for any guidance or insights into resolving this issue. Thank you in advance for your help! Best regards, Adam
Posted
by