IOS学习笔记63--截取当前图像保存至相册

来源:互联网 发布:intent传递大图片数据 编辑:程序博客网 时间:2024/06/05 09:31

码农就应该坚持写东西,防止秃顶的速度加快,嘿嘿!

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

    }

}


0 0