hey guys,
I’m working on exporting capturing-screenshots to web-based image links, but I haven’t really found a solution to this problem.
I am using cocos creator version 3.8.2. thanks all !
Take the Screenshot using #include "cocos2d.h
Use utils::captureScreen()
to capture the screen and save it to a local file.
Upload to a Server using #include “network/HttpClient.h”
Use a networking library (like cURL
or HttpClient
) to upload the image to a cloud service.
Retrieve the Public URL
Get the URL from the server response and use it in your game.
thanks for your reply, but i am using cocos creator version 3.8.2
@Tom_k sr, can you help me solve my problem?
it works in cocos3d as well
captureScreen does not exist in utils with cocos creator 3.8.2
I’m not sure I understand your problem, do you want to capture a screenshot to save locally or send to a server?
This code below will save locally
director.once(Director.EVENT_AFTER_RENDER, () => {
let camera = this.node.getComponentInChildren(Camera);
let uiTransform = this.node.getComponent(UITransform)
let width = uiTransform.width;
let height = uiTransform.height;
let texture = new RenderTexture();
texture.reset({width: width, height: height});
camera.targetTexture = texture;
let canvas = gfx.Device.canvas;
let dataURL = canvas.toDataURL("image/jpeg");
let img = document.createElement("a");
img.href = dataURL;
img.target = "_self";
img.download = "screenshot.png"
img.click()
camera.targetTexture = null;
})
you can take “dataUrl” to send to a server as base64 encoding of the screenshot image.
awesome this is exactly what i wanted thank you so much .