#pragma mark 截屏并保存至相册

-(void)screenShotsComplete:(void(^)(UIImage * img)) complete

{

CGSize imageSize = [[UIScreen mainScreen] bounds].size;

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

CGContextRef context = UIGraphicsGetCurrentContext();

for (UIWindow * window in [[UIApplication sharedApplication] windows]) {

if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {

CGContextSaveGState(context);

CGContextTranslateCTM(context, [window center].x, [window center].y);

CGContextConcatCTM(context, [window transform]);

CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y);

[[window layer] renderInContext:context];

CGContextRestoreGState(context);

}

}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

NSLog(@"Suceeded!");

if(complete){

complete(image);

}

}

//点击保存至相册后,出现动画效果

[self screenShotsComplete:^(UIImage *img) {

UIImageView * imgView=[[UIImageView alloc]initWithFrame:weakSelf.view.bounds];

imgView.image=img;

[weakSelf.view addSubview:imgView];

CGPoint center=CGPointMake(weakSelf.view.center.x, weakSelf.view.center.y-64);

[UIImageView animateWithDuration:1.0f animations:^{

imgView.width-=imgView.width;

imgView.height-=imgView.height;

imgView.alpha=0.0f;

imgView.center=center;

} completion:^(BOOL finished) {

[imgView removeFromSuperview];

btn.enabled=YES;

[HintInfoView showOnView:weakSelf.view hintTitle:@"保存成功!" hintFont:weakSelf.commonTitleFont];

}];

}];

};

iOS截屏保存至相册的更多相关文章

  1. IOS 截屏(保存到相册中)

    @interface NJViewController () /** * 点击截屏按钮 */ - (IBAction)captureView:(UIButton *)sender; /** * 白色v ...

  2. Unity3d 截屏保存到相册,并且刷新相册

    要做一个截图的功能,并且玩家可以在相册中看到. 做的时候遇到了三个问题: 1.unity自带的截图API,Application.CaptureScreenshot在Android上不生效 2.图片保 ...

  3. android截屏:保存一个view的内容为图片并存放到SD卡

    项目中偶尔会用到截屏分享,于是就有了下面这个截屏的方法~ 下面得saveImage()方法就是保存当前Activity对应的屏幕所有内容的截屏保存. private void saveImage() ...

  4. iOS 截屏分享(包含状态栏与不包含状态栏)

    iOS8以上的新方法PhotoKit 监听截图相册变化,取最后一张图片:http://www.hangge.com/blog/cache/detail_1515.html PhotoKit 获取本机相 ...

  5. ios截屏代码[转]

    http://www.cnblogs.com/chenxiangxi/p/3547974.html 这位博主的连接中将ios自定义大小位置的截屏代码写的很不错,马上就能用的方法,对于只想马上用的程序员 ...

  6. iOS截屏代码

    转载自:http://m.open-open.com/m/code/view/1420469506375 1.普通界面 /** *截图功能 */ -(void)screenShot{ UIGraphi ...

  7. iOS ----------将照片保存到相册

    在使用前  请导入photos.framework 然后导入 #import <Photos/PHPhotoLibrary.h> #import <Photos/PHAssetCha ...

  8. JS实现网页选取截屏 保存+打印 功能(转)

    源码地址: 1.1 确定截图选取范围 用户在开始截图后,需要在页面上选取一个截图范围,并且可以直观的看到,类似如下效果: image 我们的选取范围就是鼠标开始按下的那个点到鼠标拖动然后松开的那个点之 ...

  9. iOS 多张图片保存到相册问题(add multiple images to photo album)

    不知道朋友们有木有做过多图保存到系统的相册这个需求,我在用`UIImageWriteToSavedPhotosAlbum`保存图片时候,在代理回调方`didFinishSavingWithError` ...

随机推荐

  1. Android 创建Library Project(库项目)与引用操作

    由于在开发过程,为了实现未曾了解的某种效果与特定功能,而求助于网上优秀的开源项目,在使用过程中发现引用开源的Library Project(库项目),的确可以解决很多问题,而且也给出了一种思路,好的软 ...

  2. HDU1175(dfs)

    连连看 Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description ...

  3. HDU5057(分块)

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. 蓝桥网试题 java 基础练习 十六进制转十进制

    ---------------------------------------------------------------------------------------- 貌似用int类型不会超 ...

  5. 测试指南(适用于Feature/promotion/bug)

    1.提前了解需求,在需求的业务基础和开发的架构基础上分析测试关键点,给出测试策略,甚至需要准备测试数据: 2.分析需求时不要受开发影响,要有自己的分析和判断,包括测试范围,测试时间: 3.在开始测试之 ...

  6. Git中.gitignore文件的使用

      在我们使用git的时候,有时候就不想传一些与代码无关的文件到远程仓库中,比如说编译后的文件,.gitignore就可以帮助我们处理这些文件. 生成.gitignore文件 在git bash中使用 ...

  7. 11g默认审计选项

    [注:参考了maclean的网文]11g默认审计选项AUDIT_TRAIL参数的缺省值为DB,审计数据记录在数据库中的AUD$审计字典基表上.在11g中CREATE SESSION将被作为受审计的权限 ...

  8. JS冒号的作用

    JS中冒号的作用1.声明对象的成员2.switch语句分支3.三元表达式 1.声明对象的成员 var Book = { Name: '法', Price: 100, Discount : functi ...

  9. Android apk应用程序签名

    Android apk应用程序签名 分类: Android 2012-11-25 19:33 570人阅读 评论(0) 收藏 举报 一.Android Apk签名 Apk签名首先要有一个keystor ...

  10. mysql远程连接权限

    环境:mysql6.0 .Navicat Premium 用户名:root 密码:123456  本地连接无问题 远程连接mysql的时候应该碰到Navicat Premium 报错. 错误代码是11 ...