ios - 截取 UIImageView 我只需要图像 IOS
<p><p>在我的 IOS 应用程序中,我正在截取 UIImageView 的屏幕截图。非常完美,如附件照片所示。但在这里,我采用了 <code>UIImageView 内容模式</code> <strong>aspect fit</strong> 。我用过这段代码。 </p>
<pre><code>func captureView() -> UIImage {
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false,UIScreen.mainScreen().scale)//add this line
let context: CGContextRef = UIGraphicsGetCurrentContext()!
self.backView.layer.renderInContext(context)
let img: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img
}
</code></pre>
<p>我只需要 Image 的快照,而不是 ImageView。帮我解决这个问题。 <a href="/image/uQT7s.jpg" rel="noreferrer noopener nofollow"><img src="/image/uQT7s.jpg" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个代码:</p>
<pre><code>func captureView() -> UIImage() {
UIGraphicsBeginImageContext(YourimageView.frame.size)
YourimageView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil)
return img
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 截取 UIImageView 我只需要图像 IOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38716144/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38716144/
</a>
</p>
页:
[1]