【问题标题】:How do I capture a zoomed UIImageView inside of a Scrollview to crop in Android?如何在 Scrollview 中捕获缩放的 UIImageView 以在 Android 中进行裁剪?
【发布时间】:2014-02-07 09:12:44
【问题描述】:

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

我想在 android 中做同样的事情,如下面的截图所示。我该怎么做?

【问题讨论】:

标签: android crop pinchzoom


【解决方案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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-18
    • 2012-07-11
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 2016-03-29
    • 2015-12-09
    相关资源
    最近更新 更多