截图 UIImageView 我只需要图像 IOS [英] Taking Screenshot of UIImageView I need only image IOS
本文介绍了截图 UIImageView 我只需要图像 IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 IOS 应用程序中,我正在截取 UIImageView 的屏幕截图.它非常完美,如附件照片所示.但是在这里,我采用了 UIImageView content mode
aspect fit .我用过这个代码.
In my IOS App I am taking screenshot of UIImageView. It's very perfect as shown in attachment Photo. But here, I have taken UIImageView content mode
aspect fit . I've used this 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
}
我只需要 Image 的快照,而不是 ImageView.帮我解决这个问题.
Simply I need the snapshot of Image, Not the ImageView. Help me into this.
推荐答案
试试这个代码:
func captureView() -> UIImage() {
UIGraphicsBeginImageContext(YourimageView.frame.size)
YourimageView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil)
return img
}
这篇关于截图 UIImageView 我只需要图像 IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文