问题
A very large image saved at DocumentDirectory. This image is asked to be display at the image view depending on users current window that can change by zooming and dragging.
I can't load the Image at memory with it full size and then start cropping. This is so costy.
The following code gets resized(smaller,scaled) copy of the image saved on disk:
if let imageSource = CGImageSourceCreateWithURL(imageURL, nil) {
let maxSize = max(thumbSize.width, thumbSize.height) / 2.0
let options = [
kCGImageSourceThumbnailMaxPixelSize: maxSize,
kCGImageSourceCreateThumbnailFromImageIfAbsent: true
]
let scaledImage = UIImage(CGImage: CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options))
}
What I need is to get part of the image directly from disk given s specfic window rect(x, y, width, height).
How I can achieve that?
来源:https://stackoverflow.com/questions/40951534/get-part-of-image-saved-on-disk-swift