canvas icon indicating copy to clipboard operation
canvas copied to clipboard

Getting non premultiplied pixel data

Open vincaslt opened this issue 1 year ago • 0 comments

It seems like this canvas is using Skia's premultiplied surface. I have an issue where if I try to get data from transparent canvas with globalAlpha=0.5 it actually multiplies the RGB values. if I set rgb(50, 50, 50) the pixel value would contain r=25, g=25, b=25, a=128 (in decimal). This resulted in my colors seeming darker when I got canvas data with canvas.data(). I wonder if there's a build in way to get non pre-multiplied pixel data.

My current way is this:

const imageData = ctx.getImageData(
          0,
          0,
          canvasSize.width,
          canvasSize.height
        );

        const buffer = Buffer.from(imageData.data);

vincaslt avatar Jun 29 '24 20:06 vincaslt