iOS 屏幕截图

 

/**

 *  截取当前屏幕视图

 

 */

+(UIImage *)screenShotWithShotScreenView

{

 

  UIImage *iimahe =  [self screenShotWithShotView:[UIApplication sharedApplication].keyWindow];

 

    return iimahe;

}

 

/**

 *  截图

 *

 *  @param shotView 需截图的view

 */

-(UIImage *)screenShotWithShotView:(UIView *)shotView

{

    UIGraphicsBeginImageContextWithOptions(shotView.bounds.size, NO, [UIScreen mainScreen].scale);//[UIScreen mainScreen].scale 屏幕分辨率,如果缺少这个,截出来的图就会模糊

    CGContextRef context = UIGraphicsGetCurrentContext();

    [shotView.layer renderInContext:context];

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;

}

posted @ 2017-09-05 18:29  Nelsen_Chen  阅读(217)  评论(0)    收藏  举报