我有一个UIView canvas
,当我按下UIBarButton shareBarButton
时,我想在相机胶卷上保存它的屏幕截图(以及它的子视图)。但是,当我按下shareBarButton
时,相机胶卷中显示的图像是完全黑屏。
任何有关为何发生这种情况的帮助将不胜感激!我也愿意接受有关将UIViews
保存到相机胶卷上的其他(可能更好)方法的建议。
这是附加到shareBarButton
func share(sender: UIBarButtonItem) {
let masterpiece = canvas.snapshotViewAfterScreenUpdates(true)
let image = convertViewToImage(masterpiece)
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
这是将UIView canvas
转换为UIImage
func convertViewToImage(masterpiece: UIView) -> UIImage{
UIGraphicsBeginImageContextWithOptions(masterpiece.bounds.size, masterpiece.opaque, UIScreen().scale)
masterpiece.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
答案 0 :(得分:0)
截取屏幕截图:
func captureView(view: UIView) -> UIImage {
var size: CGSize = self.imageViewObject.image.size
UIGraphicsBeginImageContext(size)
self.imageViewObject.image.drawInRect(CGRectMake(0, 0, size.width, size.height))
self.imageOverLayObject.image.drawInRect(CGRectMake(0, 0, size.width, size.height))
var image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}