Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unble to save screenshot as blob #400

Open
meilleureVie opened this issue Mar 21, 2024 · 1 comment
Open

Unble to save screenshot as blob #400

meilleureVie opened this issue Mar 21, 2024 · 1 comment

Comments

@meilleureVie
Copy link

Features:

So far the only way to get the screenshot is using this.webcam.getScreenshot() which return base64 image.
But it IS also important to get the result as blob.
I would like to add also blob support

@alvesvaren
Copy link

You can pretty easily create a blob from a base64 image using something like this:

    const [, imageSrcB64] = image.split(",", 2);
    const bstr = atob(imageSrcB64);
    const u8arr = new Uint8Array(bstr.length);
    for (let i = 0; i < bstr.length; i++) {
      u8arr[i] = bstr.charCodeAt(i);
    }
    const imageBlob = new Blob([u8arr], { type: "image/jpeg" });

This assumes the image is of type jpeg, but you can use the same type as when you create the camera. (By default image/webp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants