首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ScreenShot图像-抽头周边地区

ScreenShot图像-抽头周边地区
EN

Stack Overflow用户
提问于 2014-12-16 23:08:45
回答 1查看 75关注 0票数 1

我已经实现了双击手势识别器,一旦用户点击两次,它就会在这一点上添加注释。此外,我还想种植一段沿海地区的开发点。然而,每次它返回不同大小的屏幕。

代码语言:javascript
复制
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateRecognized) {
        // handling code      
        point = [sender locationInView:sender.view];
        iViewController.noteImageView.image=[self captureView:self.view];
        [self.view addSubview:iViewController.view];
    }
}

 -(UIImage*)captureView:(UIView*)view
    {
        CGRect screenRect=CGRectMake(point.x-20,point.y-40,point.x+10,point.y+20);
        //CGRect screenRect=[[UIScreen mainScreen]bounds];
        UIGraphicsBeginImageContext(screenRect.size);

        CGContextRef ctx= UIGraphicsGetCurrentContext();
        [[UIColor blackColor]set];
        CGContextFillRect(ctx, screenRect);
        [view.layer renderInContext:ctx];

        UIImage *scImage=UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        return scImage;

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-17 00:27:52

希望这能帮上忙:

代码语言:javascript
复制
-(UIImage*)captureView:(UIView*)view forPoint:(CGPoint)point
{
    CGRect cropRect = CGRectMake(point.x-20,point.y-40,point.x+10,point.y+20);
    UIGraphicsBeginImageContext(view.bounds.size);
    CGContextRef ctx= UIGraphicsGetCurrentContext();

    [[UIColor blackColor] setFill];
    CGContextFillRect(ctx, view.bounds);
    [view.layer renderInContext:ctx];
    CGImageRef snapshot = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext());

    CGImageRef cropped = CGImageCreateWithImageInRect(snapshot, cropRect);
    UIImage *image =  [UIImage imageWithCGImage:cropped];

    UIGraphicsEndImageContext();
    CGImageRelease(snapshot);
    CGImageRelease(cropped);

    return image;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27515629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档