1

如果要截屏是ios app,可以使用以下代码:

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
currentCaptureImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但我想从特定点捕获图片,例如(start.x,start.y)并具有特定的宽度和高度,我该怎么做?

4

1 回答 1

0

我只是用谷歌搜索并从如何捕获特定大小的 self.view 中得到最佳答案

UIGraphicsBeginImageContextWithOptions(CGSizeMake(300, 320), YES, 0.);
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

例如,如果您的视图是 600x320 并且您想捕获中间 300 点的宽度,您可以将上下文向左平移 150 点:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(300, 320), YES, 0.);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context, -150.f, 0.f);
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
于 2013-02-08T06:33:43.557 回答