如何捕获Scrollview内部的缩放UIImageView以在Android中裁剪?

时间:2014-02-07 09:12:44

标签: android crop pinchzoom

我已将此链接How do I capture a zoomed UIImageView inside of a Scrollview to crop?

提及

我想在android中做同样的事情,如下面的截图所示。我可以这样做吗?

step 1

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

func getZoomedImage() - >的UIImage {

    //Calculate the required area from the scrollview
    var visibleRect = CGRect()
    let scale: CGFloat = CGFloat(1.0 / scrollViewGallery.zoomScale)
    visibleRect.origin.x = scrollViewGallery.contentOffset.x * scale
    visibleRect.origin.y = scrollViewGallery.contentOffset.y * scale
    visibleRect.size.width = scrollViewGallery.bounds.size.width * scale
    visibleRect.size.height = scrollViewGallery.bounds.size.height * scale
    let cgImg: CGImage? = imgView.image?.cgImage?.cropping(to: visibleRect)
    let croppedImg = UIImage(cgImage: cgImg!)
    return croppedImg
}