Reputation: 90
I'm capturing a full page screenshot of a UIWebView and passing the image through a segue:
// WebViewController.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "captureSegue" {
var captureViewcontroller:CaptureViewController = segue.destinationViewController as! CaptureViewController
captureViewcontroller.tempCaptureImage = image
}
}
The UIImage is then being saved to Documents/Images
in the application directory just fine. If I open it from the file system it shows just fine in Preview. However, if the screenshot is really large, the images won't show in a UIImageView. The UIImageView renders blank. Adding a breakpoint shows that the image data is there, just not rendering.
// CaptureViewController.swift
var tempCaptureImage: UIImage?
@IBOutlet weak var imageScrollView: UIScrollView!
@IBOutlet weak var captureImageView: UIImageView!
@IBOutlet weak var titleField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if let image = tempCaptureImage {
captureImageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: image.size)
captureImageView.image = image
imageScrollView.contentSize = image.size
let scrollViewFrame = imageScrollView.bounds
let scaleWidth = scrollViewFrame.size.width / imageScrollView.contentSize.width
let scaleHeight = scrollViewFrame.size.height / imageScrollView.contentSize.height
let minScale = min(scaleWidth, scaleHeight);
imageScrollView.minimumZoomScale = minScale;
imageScrollView.maximumZoomScale = 1.0
imageScrollView.zoomScale = minScale;
}
}
Could this be because the image is large? If the pages that I capture are smaller, then the images show just fine. Are there any recommended techniques for viewing large images on iDevices?
EDIT:
Here is the output of the Variables View with a breakpoint. Maybe you see something I'm missing.
Upvotes: 1
Views: 1455
Reputation: 7238
For people have similar problem, maybe tried to test in real device. For me, image with size 1000 x 7000 isn't displayed in Simulator nor Interface Builder, but can be displayed in an iPhone 6s plus.
Also, Interface Builder will complain if image size is larger than 10000 x 10000.
Upvotes: 3
Reputation: 535536
You do not give any info on how large the image actually is, so it's impossible to say what limit you might be hitting. Remember, though, that a triple-scale image multiplies the underlying bitmap memory size by 9 in comparison to a single-scale image. That's an order of magnitude! I can well believe that you would quickly exceed the memory capacity of the app and even crash if you tried to access an image that's too large. So step one would surely be to load the image as a single-scale image; see the ImageIO framework to learn how to do that. See also the docs on CATiledLayer if you want to know how to display a very large image.
Upvotes: 1