碼農就應該堅持寫東西,防止禿頂的速度加快,嘿嘿!
2104年就用這個開頭吧,好久沒寫了,頹廢了...
//截圖
-(UIImage *)captureCurrentView :(UIView *)view{
CGRect frame = view.frame;
UIGraphicsBeginImageContext(frame.size);
CGContextRef contextRef =UIGraphicsGetCurrentContext();
[view.layerrenderInContext:contextRef];
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *saveImage = [UIImageimageWithCGImage:CGImageCreateWithImageInRect(image.CGImage,CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height))];
return saveImage;
}
//保存圖片
-(void)saveImageToPhotos:(UIImage *)image{
UIImageWriteToSavedPhotosAlbum(image, self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);
}
//保存回調
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
NSString *msg = nil ;
if(error != NULL){
msg =@"保存圖片失敗" ;
}else{
msg = @"保存圖片成功" ;
}
}