ios 截屏保存图片

//私有API,目前appstore可以审核通过了(iphone目前没问题,但是ipad会出现图片变形)
CGImageRef img = UIGetScreenImage(); UIImage* scImage=[UIImage imageWithCGImage:img]; UIImageWriteToSavedPhotosAlbum(scImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

 下面这种截图,保存上下文(如果是yuv视频数据是无法直接保存,方法:视频数据时,可以采用yuv转换RGB在转换UIImage) 

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

  

判断是否截图成功

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error)
    {
        strStatus = Localized(@"Save failed");
    }
    else
    {
        strStatus = Localized(@"Save success");
    }
}

  

posted @ 2013-11-15 14:33  暖流  阅读(529)  评论(0编辑  收藏  举报