ios截屏 u3d导出Xcode工程截屏

在ios原生程序里面

全屏截屏

 UIWindow *window = [[UIApplication sharedApplication] keyWindow];  //下边是经典的4步

 

    UIGraphicsBeginImageContext(window.frame.size);  //打开画布,并设定大小

   [window.layer renderInContext:UIGraphicsGetCurrentContext()];  // u3d下 此行替换

    UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

 

指定部分截屏:接着上面做,已经获取到了全屏的(UIImage *)screenShot

 CGRect rect = CGRectMake(0, 100, K_WIDTH, 400);                  //设置 一个截屏区域

 CGImageRef imageRef = CGImageCreateWithImageInRect(_screenShot.CGImage, rect);  //注意指针没有星号

 screenShot = [UIImage imageWithCGImage:imageRef];                 //创建新图片需要一个CGImageRef的参数

 

 

一般对iOS来讲就够用了,但对于u3d导出的XCode工程来讲,这样截图会截到一片白,查看运行中XCode中的层级视图,确实一片白

通过保存到图库查看  UIImageWriteToSavedPhotosAlbum(_screenShot, nil, nil, nil); 

 

解决办法:把上面标注替换的一行换成下面

    [window drawViewHierarchyInRect:CGRectMake(0, 0, K_WIDTH, K_HEIGHT) afterScreenUpdates:YES];

posted @ 2016-11-24 12:39  binbins  阅读(262)  评论(0编辑  收藏  举报