ios开发日记- 5 屏幕截图
2015-09-14 18:01
666 查看
-(void)fullScreenshots{
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
objective c 截屏代码
-(void)save{
UIGraphicsBeginImageContext(mybackgroundview.bounds.size); //currentView 当前的view
[mybackgroundview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); //保存到相册中
}截取 您想要的一层
UIGraphicsBeginImageContext(CGSizeMake(320, 300)); //currentView 当前的view
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); //保存到相册中
截取自定义的大小
iPhone开发应用中抓图程序案例实现是本文要介绍的内容,主要是通过代码来实现抓图程序,具体实现过程,一起来看详细代码。
//获得屏幕图像
- (UIImage *)imageFromView: (UIView *) theView
{
UIGraphicsBeginImageContext(theView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[theView.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
//获得某个范围内的屏幕图像
- (UIImage *)imageFromView: (UIView *) theView atFrame:(CGRect)r
{
UIGraphicsBeginImageContext(theView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIRectClip(r);
[theView.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;//[self getImageAreaFromImage:theImage atFrame:r];
}
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
objective c 截屏代码
-(void)save{
UIGraphicsBeginImageContext(mybackgroundview.bounds.size); //currentView 当前的view
[mybackgroundview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); //保存到相册中
}截取 您想要的一层
UIGraphicsBeginImageContext(CGSizeMake(320, 300)); //currentView 当前的view
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); //保存到相册中
截取自定义的大小
iPhone开发应用中抓图程序案例实现是本文要介绍的内容,主要是通过代码来实现抓图程序,具体实现过程,一起来看详细代码。
//获得屏幕图像
- (UIImage *)imageFromView: (UIView *) theView
{
UIGraphicsBeginImageContext(theView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[theView.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
//获得某个范围内的屏幕图像
- (UIImage *)imageFromView: (UIView *) theView atFrame:(CGRect)r
{
UIGraphicsBeginImageContext(theView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIRectClip(r);
[theView.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;//[self getImageAreaFromImage:theImage atFrame:r];
}
相关文章推荐
- IOS从视频中获取截图
- iOS开发:利用SDWebImage实现图片加载与缓存
- iOS cocoapods
- iOS开发:一个瀑布流的设计与实现(已实现缓存池功能,该功能使得瀑布流cell可以循环利用)
- (转)27个提升效率的iOS开源库推荐
- IOS开发模块总结(二)后台运行程序(1) 后台运行程序详解(二)
- iOS 计算年龄
- IOS开发模块总结(二)后台运行程序(1) 后台运行程序详解(一)
- iOS开发的22个奇谲巧技
- iOS开发之摇一摇功能的实现
- iOS ios与js交互,获取webview完整url,title,获取元素并赋值跳转
- iOS开发--touchID指纹识别
- ios
- iOS--常用控件--WebView与js相互调用
- ffmpeg在iOS的使用 - iFrameExtractor源码解析
- iOS 警告收录及科学快速的消除方法
- 全面了解 iOS 静态库开发
- framework not found XCTest
- ios arc下内存管理
- FIRST TODY STAR