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

@子龙山人 怎么安卓和iOS截图区别这么大啊 安卓端截图出来只有200来KB 但是iOS截图却有差不多2MB 产品让弄小,这个要怎么搞呢

您好,如何删除上述方式保存的图片呢

兄台,这个截取任意子节点的图像的问题,搞定没?可以指教一下吗

var renderTexture = cc.RenderTexture.create(1280,640, cc.Texture2D.PIXEL_FORMAT_RGBA8888, gl.DEPTH24_STENCIL8_OES);
在设备上测试对带有Mask的组件是可以截屏的,但是在web上不可以 而且 gl.DEPTH24_STENCIL8_OES打印出来时undefined 是不是在web 有其他的解决方案

那在web平台上怎样截带Mask的节点呢,我现在也遇到这个问题了

请问截屏的相片怎么保存后能在相册里看到啊

同问~

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赞