- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在我的 SKScene 中绘制一条路径以显示我的对象的轨迹。一切正常,我可以绘制所有点的路径并将其添加到场景中。当我尝试打印我的场景时,问题发生了,除了路径之外的所有内容都出现了。我哪里做错了?
- (void)drawPathTrackBall
{
// length of my nsmutablearray with the object track
NSUInteger len = [_trackBallPath count];
// start image context
CGRect bounds = self.scene.view.bounds;
UIGraphicsBeginImageContextWithOptions(bounds.size, YES, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:bounds afterScreenUpdates:YES];
// draw my path
SKShapeNode *line = [[SKShapeNode alloc] init];
CGMutablePathRef linePath = CGPathCreateMutable();
CGPathMoveToPoint(linePath, NULL, _ballStartX, _ballStartY);
for(NSUInteger i=0; i<len; ++i)
{
NSValue *nsPoint = [_trackBallPath objectAtIndex:i];
CGPoint p = nsPoint.CGPointValue;
CGPathAddLineToPoint(linePath, NULL, p.x, p.y);
}
line.path = linePath;
line.lineWidth = 0.5f;
line.strokeColor = [UIColor redColor];
[_container addChild:line];
_screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
谢谢
最佳答案
首先 - 您正在创建简单的路径,它没有连接或绘制到您代码中的某个地方到上下文。我还没有学过 SpriteKit,但我很了解 CoreGraphics,我认为你不能简单地使用那里的 SpriteKit API 来创建屏幕截图。而是尝试使用 native CoreGraphics 方法。
要使您的代码正常工作,您需要:
获取您将绘制的上下文。
因为您已经创建了路径 - 只需将其添加到上下文即可。
然后描边/填充它。
要获取绘制调用的当前上下文:CGContextRef ctx = UIGraphicsGetCurrentContext();
添加路径使用:CGContextAddPath(ctx, path);
描边/填充使用 CGContextStrokePath(ctx);
/CGContextFillPath(ctx);
所以你更新后的代码应该是这样的(注意我已经删除了与 SpriteKit 相关的代码):
- (void)drawPathTrackBall
{
// length of my nsmutablearray with the object track
NSUInteger len = [_trackBallPath count];
// start image context
CGRect bounds = self.scene.view.bounds;
UIGraphicsBeginImageContextWithOptions(bounds.size, YES, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:bounds afterScreenUpdates:YES];
CGContextRef ctx = UIGraphicsGetCurrentContext(); // Obtain context to draw.
CGMutablePathRef linePath = CGPathCreateMutable();
CGPathMoveToPoint(linePath, NULL, _ballStartX, _ballStartY);
for(NSUInteger i=0; i<len; ++i)
{
NSValue *nsPoint = [_trackBallPath objectAtIndex:i];
CGPoint p = nsPoint.CGPointValue;
CGPathAddLineToPoint(linePath, NULL, p.x, p.y);
}
// I've exchanged SpriteKit node API calls with CoreGraphics equivalents.
CGContextSetLineWidth(ctx, 0.5f);
CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor);
CGContextAddPath(ctx, linePath);
CGContextStrokePath(ctx);
_screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
试一试。
关于ios - 路径在 UIGraphicsBeginImageContextWithOptions 下不可见 - SpriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21915503/
所以我有一个函数可以拍摄两张图像并将它们组合起来。也许图像太大,因为当我尝试使用 2 个较小的图像时,效果很好,但我不确定。所以我用相机拍了一张照片,然后尝试从相册中打开它。我选择图像并使用此函数将其
我正在努力适应THIS问题与视网膜显示器一起使用。以下是我如何弄清楚如何使用 UIGraphicsBeginImageContext 的视网膜图形。 if (UIGraphicsBeginImageC
我只是进行签名并使用 imageMask 进行保存。实际上,imageMask 渲染正确,但主签名行为异常,如其中的 2 行。这是我的代码。 UIGraphicsBeginImageContextWi
在使用 UIGraphicsBeginImageContextWithOptions 截屏时,是否有隐藏特定按钮(IBAction)的方法? 我正在使用下面的代码: // Define the di
我有这行代码来截取 uiview 的屏幕截图: - (UIImage *)imageWithView:(UIView *)view { UIImage *viewImage = nil
一段时间以来,我一直在努力使用这种方法。我正在另一张图片上绘制头像。用户图片我想成为一个圆圈,但我似乎无法弄清楚如何。用户图片是 UIImage 而不是 UIImageView。如果它是 ImageV
我使用下面的函数来渲染图像,但返回的图像底部有不需要的边框。 public func renderTextOnView(view: UIView) -> UIImage? { UIGraphi
我对 UIGraphicsBeginImageContextWithOptions 和线程有点困惑,因为根据 UIKit Function Reference UIGraphicsBeginImage
在我正在开发的应用程序中,客户输入一些个人信息并在屏幕上的一个框中签名。然后我以编程方式截取完整 View 并将其转换为 base64。 这工作正常,但是,由于图像的大小,将其转换为 base64 并
问题 我正在使用 UIGraphicsBeginImageContextWithOptions 将屏幕截图保存到 UIImage 中。虽然这有效,但生成的 UIImage 缺少任何阴影和渐变。 如何让
我需要绘制这样的图像 提供的是:带向下箭头图像的绿色气泡(绿色气泡图像已经有边框,所以我不需要绘制它)和中心照片。我需要在照片周围绘制白色边框 + 圆角这是我到目前为止的代码: let rect =
我正在开发 iOS 应用程序。它目前仅适用于 iOS 4,因为我多次使用以下方法:“UIGraphicsBeginImageContextWithOptions”。此方法仅在 iOS 4 中可用,因此
我正在我的 SKScene 中绘制一条路径以显示我的对象的轨迹。一切正常,我可以绘制所有点的路径并将其添加到场景中。当我尝试打印我的场景时,问题发生了,除了路径之外的所有内容都出现了。我哪里做错了?
我正在使用 SDWebImage 下载缩略图。在使用 - (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDown
我有一个函数 UIGraphicsBeginImageWithContextWithOptions()和 UIGraphicsEndImageContext( ,但该函数已经传递了一个名为“conte
所以我有这段代码来创建一个 UIImage: UIGraphicsBeginImageContextWithOptions(border.frame.size, YES, 0); [border.la
我正在寻找一种解决方案来将 UIView(及其 subview )保存为图像到设备照片库。我希望输出图像的大小为 1024 x 1024。UIView 将始终是一个正方形,因此 subview 将适合
使用此类方法并创建纯色 UIImage 会比创建纯色 png 更快吗? + (UIImage*) imageWithColor:(UIColor*)color size:(CGSize)size {
在绘制到屏幕外缓冲区时,我很难让 Image Insets 正常工作。 在 UIImage 上直接使用 resizableImageWithCapInsets: setImage: into a bu
我曾经使用以下代码调整图像大小,它过去在比例因子方面工作得很好。现在使用 Swift 3 我无法弄清楚为什么不考虑比例因子。图像已调整大小但未应用比例因子。你知道为什么吗? let layer = s
我是一名优秀的程序员,十分优秀!