Screenshot issues

I would like to ask how I can intercept the image from a specified camera on my mobile phone and store it locally?

Original Post on Discord

by user 417248803431776267

Hi, you can just import the screenshot method and call that:

import { screenshot } from "@needle-tools/engine" and call it

For saving the image you can do something like this with the string you get from the screenshot method:

export function saveImage(dataUrl: string | null, filename: string) {
    if (!dataUrl) {
        return;
    }
    if (!dataUrl.startsWith("data:image")) {
        console.error("Can not save image: Data url is not an image", dataUrl);
        return;
    }
    const saveImageElement = document.createElement("a");
    saveImageElement.href = dataUrl;
    saveImageElement.download = filename;
    saveImageElement.click();
}

If you just want to save the current/last frame you can do it like this:

const dataUrl = this.context.renderer.domElement.toDataURL("image/png");
// and then call save Image:
saveImage(dataUrl, "myImage.png");