经验分享:Creator 原生平台截屏方案

gl.DEPTH24_STENCIL8_OES web平台没么对 Mask失效!!!

在web上已经解决mask问题 renderTexture = new cc.RenderTexture(size.width, size.height, cc.ImageFormat.PNG, gl.DEPTH_STENCIL);

1赞

mark 日后来看

android 截图存放路径在系统文件夹下 没有root 怎么访问 怎样修改图片存放路径

1赞

希望官方可以出截屏的方案,这个问题好难弄

panda说2.0有官方的接口

场景中有半透明图片截出来的图片偏暗怎么解决呀

打包成原生项目后,怎么找到你们的绘制方法,目前我调用了Android原生的截图方法,但是这种方式只能在5.0以后的手机上使用,另一种方式需要用到你们的绘制方法,原生项目的绘制方法在哪里?

iphone 的Google浏览器怎么做全屏啊:joy:

预览版有吗

挖坟,

// 截屏返回 iamge base6
public getImgBase64() {
const target = this.node.getComponent(cc.Canvas);
const width = 720;
const height = 1280;
const renderTexture = new cc.RenderTexture(width, height);
renderTexture.begin();
target.node._sgNode.visit();
renderTexture.end();
//
const canvas = document.createElement(“canvas”);
const ctx = canvas.getContext(“2d”);
canvas.width = width;
canvas.height = height;
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
const texture = renderTexture.getSprite().getTexture();
const image = texture.getHtmlElementObj();
ctx.drawImage(image, 0, 0);
} else if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
const buffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, buffer);
const texture = renderTexture.getSprite().getTexture()._glID;
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
const data = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
const rowBytes = width * 4;
for (let row = 0; row < height; row++) {
const srow = height - 1 - row;
const data2 = new Uint8ClampedArray(data.buffer, srow * width * 4, rowBytes);
const imageData = new ImageData(data2, width, 1);
ctx.putImageData(imageData, 0, row);
}
}

  const url =  canvas.toDataURL("image/png");
  cc.log("url", url);

  return url;

}
}

it works, my code snippet goes like:

let renderTexture: cc.RenderTexture
if (cc.sys.isNative) {
  renderTexture = new cc.RenderTexture(cc.winSize.width, cc.winSize.height, cc.Texture2D.PIXEL_FORMAT_RGBA8888, gl.DEPTH24_STENCIL8_OES)
} else {
  renderTexture = new cc.RenderTexture(cc.winSize.width, cc.winSize.height, cc.ImageFormat.PNG, gl.DEPTH_STENCIL)
}
const canvas: cc.Node = cc.director.getScene().getChildByName('Canvas')

renderTexture.begin()
canvas._sgNode.visit()
renderTexture.end()

const nowFrame: cc.SpriteFrame = renderTexture.getSprite().getSpriteFrame()
const outerMask: cc.Node = this.rankPage.getChildByName('outer-bg')
outerMask.getComponent(cc.Sprite).spriteFrame = nowFrame
outerMask.runAction(cc.flipY(true));
1赞

mark

在iPhone上,频繁点击截图,偶现截出的图是黑屏的,请问可能是什么原因

2.0 原生 平台截屏怎么用啊? 大佬给个方法吧

不管 this.richText.node的锚点设置多少,或者 this.richText.node的position设置多少,截取的起始位置都是在屏幕的中心点。 如果把“this.richText.node._sgNode.visit();”改成“this.richText._sgNode.visit();”,截取的起始位置是锚点位置,但是截取的图片不包含子节点,想问一下:怎么设置截取的起始位置?

一圈下来,感觉截图好复杂

@子龙山人2.0原生版怎么截屏啊
begin函数用不了

兄弟看文档,摄像机截图