你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS學習筆記63--截取當前圖像保存至相冊

IOS學習筆記63--截取當前圖像保存至相冊

編輯:IOS開發綜合

碼農就應該堅持寫東西,防止禿頂的速度加快,嘿嘿!

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 = @"保存圖片成功" ;

}

}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved