iOS下截屏的几种方法
来源:互联网 发布:clock置换算法实例讲解 编辑:程序博客网 时间:2024/06/10 04:42
- (UIImage *) imageWithView1:(UIView *)view{ UIImage *img; UIGraphicsBeginImageContext(view.bounds.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img;}
-(UIImage *)GetScreenShotWithScreen:(UIView *)Screen andFrame:(CGRect)frame{ UIGraphicsBeginImageContext(Screen.frame.size); [Screen.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * shotImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CGImageRef shotRef = shotImage.CGImage; CGImageRef ResultRef = CGImageCreateWithImageInRect(shotRef, frame); UIImage * Result = [UIImage imageWithCGImage:ResultRef]; CGImageRelease(ResultRef); return Result;}
//获得某个范围内的屏幕图像- (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];}
UIImage *img; UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0); [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img;
截屏模糊问题
这个方法截屏会模糊
UIGraphicsBeginImageContext(CGSize size);
第二种方法,argument:size大小 opaque透明度 scale缩放比例
UIGraphicsBeginImageContextWithOptions(CGSize size,BOOL opaque, CGFloat scale);
参考如下:
Parameters
- size
The size (measured in points) of the new bitmap context. This represents the size of the image returned by the
UIGraphicsGetImageFromCu
rrentImageContext function. To get the size of the bitmap in pixels, you must multiply the width and height values by the value in the scale parameter. - opaque -- 不透明(YES)
A Boolean flag indicating whether the bitmap is opaque. If you know the bitmap is fully opaque, you can specify
YES
for this parameter to optimize the bitmap storage. Specifying NO
means that the bitmap must include an alpha channel to handle any partially transparent pixels. - scale
The scale factor to apply to the bitmap. If you specify a value of
0.0
, the scale factor is set to the scale factor of the device’s main screen.
- iOS下截屏的几种方法
- iOS延时执行的几种方法
- ios监听的几种方法比较
- IOS截屏的几种方法
- ios 图片拉伸的几种方法
- ios多线程的几种方法
- IOS图片拉伸的几种方法
- iOS 播放音频的几种方法
- iOS 播放音频的几种方法
- iOS隐藏键盘的几种方法
- iOS 播放音频的几种方法
- iOS 播放音频的几种方法
- iOS 播放音频的几种方法
- IOS清理缓存的几种方法
- iOS 播放音频的几种方法
- iOS 播放音频的几种方法
- iOS 播放音频的几种方法
- iOS 播放音频的几种方法
- Android Studio开发入门-引用jar及so文件
- 分页控件:pager-taglib与SpringMVC结合实例
- MFC 更改控件颜色
- Uva - 202 - Repeating Decimals
- VS2010编写exe程序,在其他电脑上无法运行,提示缺少mfc100.dll的解决办法
- iOS下截屏的几种方法
- 主题切换及其管理
- 实现一个字符串中的文字显示多种颜色
- Tiny模板引擎之工具介绍
- Android中Gridview和ViewPager显示图片的优化处理(2)
- Redis dictScan反向二进制迭代器
- 隐马尔科夫学习七(一)
- php webService wsdl
- 【知识点】增量式编码器的工作原理和使用方法