Ard*_*mur 1 xcode screenshot objective-c screen-capture ios
我想以特定大小拍摄特定位置的屏幕截图.我找到了这个.但它需要整个屏幕.我在哪里可以设置CGRect.
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
Jor*_*ith 13
几天前我被困在了这个......然后过了一会儿我设法找到了解决方案!我已经在一个类别中实现了它:
#import "UIView+RenderSubframe.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIView (RenderSubframe)
- (UIImage *) renderWithSubframe:(CGRect)frame {
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextConcatCTM(c, CGAffineTransformMakeTranslation(-frame.origin.x, -frame.origin.y));
[self.layer renderInContext:c];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenshot;
}
@end
Run Code Online (Sandbox Code Playgroud)
瞧!
如果我没有弄错的话,这种方法实际上根本不会渲染视图中不需要的部分,这使得它比之后裁剪图像更有效.
在您的情况下,您希望将此类别应用于UIWindow类而不是UIView.
| 归档时间: |
|
| 查看次数: |
4317 次 |
| 最近记录: |