- (void)viewDidLoad {
[super viewDidLoad];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
view.backgroundColor=[UIColor purpleColor];
[self.view addSubview:view];
[self save];
}
//保存到手机相册把截屏图片
- (void)save{
UIImage *image=[self getNormalImage:self.view];UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
//去截屏
float width = [UIScreen mainScreen].bounds.size.width;
float height = [UIScreen mainScreen].bounds.size.height;
UIGraphicsBeginImageContext(CGSizeMake(width, height));
//获取绘图上下文 可以理解为画布
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}