我试图让用户能够分享一个应用程序的截图并分享它。我已经得到了一个截图和分享,但有兴趣找出是否有人知道如何添加一层文字上的截图时,正在采取的,有点像一个水印。
我在这里截图:
let layer = UIApplication.sharedApplication().keyWindow!.layer
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
layer.renderInContext(UIGraphicsGetCurrentContext()!)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let croppedImage = self.cropImage(screenshot)
let activityViewController = UIActivityViewController(activityItems: [croppedImage], applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
我在此功能中裁剪屏幕截图图像,使其仅显示屏幕中间:
func cropImage(screenshot: UIImage) -> UIImage {
let scale = screenshot.scale
let imgSize = screenshot.size
let screenHeight = UIScreen.mainScreen().bounds.height
let bound = self.view.bounds.height
let navHeight = self.navigationController!.navigationBar.frame.height
let bottomBarHeight = screenHeight - navHeight - bound
let crop = CGRectMake(0, 200, //"start" at the upper-left corner
(imgSize.width - 1) * scale, //include half the width of the whole screen
(imgSize.height - bottomBarHeight - 300) * scale) //include the height of the navigationBar and the height of view
let cgImage = CGImageCreateWithImageInRect(screenshot.CGImage, crop)
let image: UIImage = UIImage(CGImage: cgImage!)
return image
}
1条答案
按热度按时间bf1o4zei1#
是的,这是可能的。尝试添加子视图到您的图像视图,如下所示