【发布时间】:2017-05-09 10:36:02
【问题描述】:
我正在尝试使用屏幕截图的方法将我的背景的模糊图像添加到场景中——正如在 here 和其他地方简要概述的那样。
但是,在我的视网膜屏幕上,叠加的图像是 1024 x 768 而不是 2048 x 1536。这使得它在屏幕上显得非常小。如何通过调整此代码来叠加正确大小的图像?
func blurWithCompletion() {
if let effectNode = scene?.childNode(withName: "effectsNode") as? SKEffectNode {
let blur = CIFilter(name: "CIGaussianBlur", withInputParameters: ["inputRadius": 10.0]);
effectNode.filter = blur;
effectNode.shouldRasterize = true;
effectNode.shouldEnableEffects = true;
UIGraphicsBeginImageContextWithOptions((view?.frame.size)!, true, 2.0)
view?.drawHierarchy(in: (view?.frame)!, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let node = SKSpriteNode(texture: SKTexture(image: image!));
effectNode.addChild(node);
}
}
编辑:view?.frame.size 为 1024 x 768;图像大小相同。
【问题讨论】:
-
编辑您的问题并添加什么视图?.frame.size!说。对
image(image.size) 执行相同的操作。还要将此行UIGraphicsBeginImageContextWithOptions((view?.frame.size)!, true, 2.0)更改为:UIGraphicsBeginImageContextWithOptions((view?.frame.size)!, true, 0.0) -
@Whirlwind 谢谢,见上文。
-
这是在您将 scale 参数设置为 0.0 之前还是之后?
-
这是以前的。将参数设置为 2.0 并不会改变它。
标签: swift sprite-kit