Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIBezierPath:视图屏幕截图的检索不正确_Iphone_Ios_Ipad_Screenshot_Uibezierpath - Fatal编程技术网

Iphone UIBezierPath:视图屏幕截图的检索不正确

Iphone UIBezierPath:视图屏幕截图的检索不正确,iphone,ios,ipad,screenshot,uibezierpath,Iphone,Ios,Ipad,Screenshot,Uibezierpath,我照下面的截图 - (UIImage*)screenshot { UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext();

我照下面的截图

- (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
绘制路径

我得到的截图是这样不正确的

你知道为什么上半部是空白的吗?在UIView上,所有图形均正确显示

- (UIImage*)screenshot :(UIView*)vw
{

    CGRect rect = [vw bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [vw.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

更新:当我用
UIBezierPath
绘制一条长路径时会发生这种情况,当我释放画笔并获得屏幕截图时,它会正确地获得屏幕截图

- (UIImage*)screenshot :(UIView*)vw
{

    CGRect rect = [vw bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [vw.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
用这个

-(IBAction)takeScreenShot:(id)sender
{

    UIGraphicsBeginImageContext(self.view.bounds.size); 

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}

使用这个

我看到了你发布的另一个帖子。
-(IBAction)takeScreenShot:(id)sender
{

    UIGraphicsBeginImageContext(self.view.bounds.size); 

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
根据,需要首先调整几何图形坐标。 因此,在渲染窗口层之前,请先执行以下操作

// -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);

我看到了你贴的另一个帖子。 根据,需要首先调整几何图形坐标。 因此,在渲染窗口层之前,请先执行以下操作

// -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);

遵循这个链接:我也尝试过这样做,但图像仍然不正确。我想问题在于如何将其数据映射到图层。请回答:这是一样的,伙计们,你们有没有其他方法可以使用CoreGraphics?请点击以下链接:我也尝试过这种方法,但图像仍然不正确。我想问题在于如何将其数据映射到图层。请回答:这是一样的,伙计们,你们有没有其他选择使用CoreGraphics?基本上,你们的解决方案与我的没有什么不同。采取这种方式也存在同样的问题。基本上你的解决方案和我的没有什么不同。采取这种方式也存在同样的问题。