美文网首页
iOS 截屏 保存到相册

iOS 截屏 保存到相册

作者: Cz1024 | 来源:发表于2016-07-20 13:47 被阅读300次

1.截取指定的view

-(UIImage *)captureImageFromViewLow:(UIView *)orgView {

//获取指定View的图片

UIGraphicsBeginImageContextWithOptions(orgView.bounds.size, NO, 0.0);

CGContextRef context = UIGraphicsGetCurrentContext();

[orgView.layer renderInContext:context];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

2.截取View上任意位置 ,顺带保存到相册

- (void)saveQRCodeImgToPhotoAlbum{

UIGraphicsBeginImageContextWithOptions(CGSizeMake(LCDW, LCDH), NO, 0.0);    //设置截屏大小

//    UIGraphicsBeginImageContext(CGSizeMake(LCDW,LCDH));

[[self layer] renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGImageRef imageRef = viewImage.CGImage;

CGRect rect = CGRectMake(2*self.bgroundView.frame.origin.x,2*self.bgroundView.frame.origin.y-15, 2*self.bgroundView.frame.size.width,2*self.bgroundView.frame.size.height);//这里可以设置想要截图的区域

CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);

UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];

UIImageWriteToSavedPhotosAlbum(sendImage, self, @selector ( image:didFinishSavingWithError:contextInfo:), nil);//保存图片到照片库

}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo

{

if (error == nil) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];

[alert show];

}else{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败,你的设置里的隐私设置,可能拒绝了,XXXXX访问你的照片" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];

[alert show];

}

}

相关文章

  • iOS 截屏 保存到相册

    1.截取指定的view -(UIImage *)captureImageFromViewLow:(UIView *...

  • ios 截屏功能(高清图)

    可以通过以下代码实现截屏,然后保存到相册。

  • ios MobileVLCKit的截屏和录屏功能

    第一、截屏功能 项目需求,点击截屏按钮,对当前直播页面截屏并且保存到相册。 MobileVLCKit这个库本身有提...

  • 浅析APP截屏唤起功能设计

    谈到APP截屏,人们的印象中就是截屏后系统会自动将截屏的图片会保存到手机相册里面,APP自己不做处理。事实上,很多...

  • 文章详情页截屏分享

    用户阅读文章详细页有截屏行为时,目前在产品上没有任何提示,是单纯的截屏自动保存到手机相册。而我们可以优化对用户截屏...

  • 对控件截屏并保存到系统相册

    前言 项目中有个需求就是对某个控件截屏,并将截屏的图片保存到系统相册。这里记录下我的实现过程。 实现过程 在具体实...

  • iOS开发-截屏

    项目需要做个截屏并保存到相册的功能,于是去网上搜了下,大部分是采用的以下方式: 不过要做的项目需要截屏的是播放视频...

  • iOS 10 截屏保存到相册

    截屏保存到相册 保存相册回调 可以做相应的动画化提示-(void)image:(UIImage *)image d...

  • flutter:截屏

    1.flutter-截屏组件 2.flutter-截屏插件 3.flutter-iOS原生截屏 iOS代码 4.获...

  • (最新)iOS截屏

    ios webview 截屏:ios截屏 前言:介绍一下截屏有很多种做法1:截当前屏幕内容2:截整个视图的所有内容...

网友评论

      本文标题:iOS 截屏 保存到相册

      本文链接:https://www.haomeiwen.com/subject/viuvjttx.html