截圖並保存到相冊

//截圖

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

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章