UIBezierPath:视图截图的检索不正确 [英] UIBezierPath : Incorrect retrieval of view screenshot

查看:189
本文介绍了UIBezierPath:视图截图的检索不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照以下方式截取屏幕截图。

I'm taking the screenshot following way.

- (UIImage*)screenshot 
{
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    CGRect rect = [keyWindow bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [keyWindow.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

在UIView上我使用 UIBezierPath <绘制路径/ code>。

On UIView I'm drawing paths using UIBezierPath.

我得到的屏幕截图不正确

The screenshots that I'm getting are incorrect like this

任何想法为什么上半部分是空白?在UIView上,所有绘图都正确显示。

Any ideas why the upper part is cut to blank ? On UIView all drawing is displayed correctly.

更新:当我用 UIBezierPath 当我发布我的画笔并获得屏幕截图时,它会正确获取截图。

UPDATE : This happens when I draw a long path with UIBezierPath when I release the my brush and get the screenshot it gets the screenshot correctly.

推荐答案

我看到了你发布的另一个帖子。
根据苹果技术Q& A ,您需要先调整几何坐标。
所以,在渲染窗口层之前,先做一些事情。

I saw the another thread which you post. According to the apple technical Q&A, you need to adjust the geometry coordinate first. So, before render the layer of window, do following things first.

// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [window center].x, [window center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [window transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
                      -[window bounds].size.width * [[window layer] anchorPoint].x,
                      -[window bounds].size.height * [[window layer] anchorPoint].y);

这篇关于UIBezierPath:视图截图的检索不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆