这是我的代码..
extern CGImageRef UIGetScreenImage();
CGRect frame = CGRectMake(0, 0, 320, 548);
CGImageRef cgoriginal = UIGetScreenImage();
CGImageRef cgimg = CGImageCreateWithImageInRect(cgoriginal, frame);
UIImage *viewImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgoriginal);
CGImageRelease(cgimg);
需要截屏但不是全屏。我在CGRect框架中知道这个问题。但我不知道,如何解决这个问题......
答案 0 :(得分:0)
请注意UIGetScreenImage是私有API,因此会被拒绝。如果你想做类似的事情你可以尝试在窗口层使用-renderInContext或-drawViewHierchyInRect(只有ios7)。 此方法应该用作UIView上的类别:
- (UIImage *) imageByRenderingViewOpaque:(BOOL) yesOrNO {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, yesOrNO, 0);
if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
}
else {
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
您还可以在UIScree实例- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates
上调用此方法,但这将只返回视图而不是图像。