Post

Replies

Boosts

Views

Activity

Reply to What is the current proper way to load an image from local filesystem?
Avoid using UIImage(contentsOfFile:), as it can lead to excessive memory consumption, especially with large images. Instead, AsyncImage works perfectly, even with local files. Here’s an example: AsyncImage(url: url) { image in image .resizable(resizingMode: .stretch) .scaledToFit() } placeholder: { Rectangle() } AsyncImage efficiently handles image loading and display, reducing the risk of memory issues.
Topic: App & System Services SubTopic: General Tags:
Jan ’25
Reply to [PHPicker] Permission error followed by "no such file" error
Bug is still alive. Env: iPad 7-gen, iPad OS 14.2 itemProvider.loadDataRepresentation(forTypeIdentifier: UTType.image.identifier) { [weak self] (data, error) in 		guard let data = data else { 				self?.parent.isPresented = false 				return 		} 		if let error = error { 				self?.parent.isPresented = false 		} 		let sourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary 		guard let source = CGImageSourceCreateWithData(data as CFData, sourceOptions) else { 				return 		} 		let downsampleOptions = [ 				kCGImageSourceCreateThumbnailFromImageAlways: true, 				kCGImageSourceCreateThumbnailWithTransform: true, 				kCGImageSourceThumbnailMaxPixelSize: 1024, 		] as CFDictionary 		guard let cgImage = CGImageSourceCreateThumbnailAtIndex(source, 0, downsampleOptions) else { 				return 		} 		let destinationData = NSMutableData() 		guard let imageDestination = CGImageDestinationCreateWithData(destinationData, kUTTypeJPEG, 1, nil) else { 				return 		} 		 		// Don't compress PNGs, they're too pretty 		let isPNG: Bool = { 				guard let utType = cgImage.utType else { return false } 				return (utType as String) == UTType.png.identifier 		}() 		let destinationProperties = [ 				kCGImageDestinationLossyCompressionQuality: isPNG ? 1.0 : 0.75 		] as CFDictionary 		CGImageDestinationAddImage(imageDestination, cgImage, destinationProperties) 		CGImageDestinationFinalize(imageDestination) 		DispatchQueue.main.async { 				self?.parent.pickedPhoto = destinationData as Data 		} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20