我已将此链接How do I capture a zoomed UIImageView inside of a Scrollview to crop?
提及我想在android中做同样的事情,如下面的截图所示。我可以这样做吗?
答案 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
}