0
votes

I have problem with this block of code.

ctx.drawImage(document.getElementById("videoScreen"), 0, 0);
imgData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height).data;
if (sendFullScreenshot || lastFrame == undefined) {
    sendFullScreenshot = false;
    croppedFrame = new Blob([electron.nativeImage.createFromDataURL(ctx.canvas.toDataURL()).toJpeg(100), new Uint8Array(6)]);
}

The error is:

Image of error

Can someone help me?

1
fix method name from toJpeg to toJPEG, docs here: electronjs.org/docs/api/native-image#imagetojpegqualitynum8er
Welcome to Stackoverflow. Your error message is telling you whats wrong! The correct method name is toJPEG() as per the documentation here electronjs.org/docs/api/native-image#native-imagetojpegbcperth
Thank you @bcperth , you helped me a lotqwerty asdfg

1 Answers

0
votes

There is no method: .toJpeg

if You check manual You'll see that it's toJPEG

image.toJPEG(quality)

  • quality Integer (required) - Between 0 - 100.

Returns Buffer - A Buffer that contains the image's JPEG encoded data.

So fix:

croppedFrame = new Blob([
  electron.nativeImage
          .createFromDataURL(ctx.canvas.toDataURL())
          .toJPEG(100), 
  new Uint8Array(6)
]);