完整截屏
来源:互联网 发布:易知投资待遇 编辑:程序博客网 时间:2024/05/19 22:05
终于找到了个完整的截屏代码,之前的截屏代码有个问题,当在图上面画东西的时候,新画上的不会被截入图片.那是因为layer问题,这下找了个好用的.
CGImageRef UIGetScreenImage();
void SaveScreenImage(NSString *path)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGImageRef cgImage = UIGetScreenImage();
void *imageBytes = NULL;
if (cgImage == NULL) {
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
imageBytes = malloc(320 * 480 * 4);
CGContextRef context = CGBitmapContextCreate(imageBytes, 320, 480, 8, 320 * 4, colorspace, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorspace);
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
CGRect bounds = [window bounds];
CALayer *layer = [window layer];
CGContextSaveGState(context);
if ([layer contentsAreFlipped]) {
CGContextTranslateCTM(context, 0.0f, bounds.size.height);
CGContextScaleCTM(context, 1.0f, -1.0f);
}
[layer renderInContext:(CGContextRef)context];
CGContextRestoreGState(context);
}
cgImage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
}
NSData *pngData = UIImagePNGRepresentation([UIImage imageWithCGImage:cgImage]);
CGImageRelease(cgImage);
if (imageBytes)
free(imageBytes);
[pngData writeToFile:path atomically:YES];
[pool release];
}
但是请注意:
The private UIGetScreenImage(void) API can be used to capture the contents of the screen:
The private UIGetScreenImage(void) API can be used to capture the contents of the screen:
0 0
- iPhone完整截屏
- 完整截屏
- Delphi6控件内容完整截屏
- 完整
- C#完整的截屏源代码及注释
- 完整的Android源码截屏事件的捕获--5.0
- 视图横屏不能完整显示
- 【android4.3】记一次完整的android源码截屏事件的捕获(不同于网上的老版本)
- asp.net 弹出div且锁屏完整代码
- 竖屏小游戏--喵星战争源码分析【完整】
- 竖屏小游戏--喵星战争源码分析【完整】
- 如何在xcode simulator保存完整的横屏图片
- 完整迁移
- 完整例子
- 完整端口扫描
- ssh 完整
- 完整通讯录
- 集合完整
- 有用的小代码
- 常用正则表达式
- 十六进制字符串转换成中文
- IOS开源项目汇总
- IOS开发中判断文件是否存在,不存在则拷贝[转]
- 完整截屏
- iOS相关架构图
- 如何把UIView转成UIImage,解决模糊失真问题
- 给UIImageView增加点击事件
- iOS单例
- ios-gzip压缩和解压缩
- 获得ios设备的一些信息
- MFC——ComBox用法大全
- CMTimeMakeWithSeconds & CMTimeMake