Drawing PNG to a canvas element — not showing transparency

前端 未结 5 1140
耶瑟儿~
耶瑟儿~ 2020-12-16 10:24

I\'m trying to use drawImage to draw a semi-transparent PNG on a canvas element. However, it draws the image as completely opaque. When I look at the resource that\'s being

5条回答
  •  时光取名叫无心
    2020-12-16 10:56

    NB, if you was to use canvas.toDataURL and you set the mimetype to anything other than say gif or png, the transparent parts of the image will be completely black.

    drawing = new Image();
    drawing.onload = function () {
        context.drawImage(drawing,0,0);
        var base64 = canvas.toDataURL('image/png', 1);
    };
    drawing.src = "draw.png";
    

提交回复
热议问题