Get part of image saved on disk (Swift)

孤者浪人 提交于 2019-12-25 16:41:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!