简体   繁体   中英

How do I capture a zoomed UIImageView inside of a Scrollview to crop in Android?

i have reffered this link How do I capture a zoomed UIImageView inside of a Scrollview to crop?

i want to do the same thing in android as shown in screenshots below.how can i do it ?

第1步

在此输入图像描述

在此输入图像描述

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM