【iOS开发】代码实现屏幕截图功能,也可以截取某个视图模糊效果

  


安康;(UIImage  *) viewSnapshot: (UIView  *) view  withInRect:矩形(CGRect中);   {   ,,,UIGraphicsBeginImageContext (view.bounds.size);   ,,,(view.layer  renderInContext: UIGraphicsGetCurrentContext ());   ,,,UIImage  * p_w_picpath =, UIGraphicsGetImageFromCurrentImageContext ();   ,,,UIGraphicsEndImageContext ();   ,,,p_w_picpath =, (UIImage  p_w_picpathWithCGImage: CGImageCreateWithImageInRect (p_w_picpath.CGImage矩形)];   ,,,return  p_w_picpath;   }

UIImage  * shotImage =, [[UIImage  alloc], init);   [self  viewSnapshot: testView  withInRect: testView.bounds];

,,,,,,,

- (void) fullScreenshots {   ,,,AppDelegate  * AppDelegate =, [UIApplication  sharedApplication] .delegate;   ,,,UIWindow  * screenWindow =, appDelegate.window;   ,,,UIGraphicsBeginImageContext (screenWindow.frame.size);   ,,,(screenWindow.layer  renderInContext: UIGraphicsGetCurrentContext ());   ,,,UIImage  * p_w_picpath =, UIGraphicsGetImageFromCurrentImageContext ();   ,,,UIGraphicsEndImageContext ();   ,,,UIImageWriteToSavedPhotosAlbum (p_w_picpath, nil,, nil,, nil);,//将截图存入相册   }

,GPUImageView  * testView =, [[GPUImageView  alloc], initWithFrame: self.view.bounds);=,testView.clipsToBounds 是的;=,,testView.layer.contentsGravity  kCAGravityTop;

,,,,,,,,

,GPUImageGaussianBlurFilter  * blurFilter =, [[GPUImageGaussianBlurFilter  alloc], init);=,blurFilter.blurRadiusInPixels  5.0 f;

,,,,,,,,

,GPUImagePicture  * picture =, [[GPUImagePicture  alloc], initWithImage: [self  fullScreenshots]];   ,[picture  addTarget blurFilter):;   ,[blurFilter  addTarget testView):;   ,(picture  processImageWithCompletionHandler: ^ {   ,[blurFilter  removeAllTargets];   ,}];

,,,,,,,,

【iOS开发】代码实现屏幕截图功能,也可以截取某个视图模糊效果