Drawing PNG to a canvas element — not showing transparency

前端 未结 5 1158
耶瑟儿~
耶瑟儿~ 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:43

    If you are drawing it in a render loop, you need to make sure to run context.clearRect( 0, 0, width, height ) first, otherwise you are just writing the png over the png every frame, which will eventually be opaque. (But frames render fast, so you wouldn't see this with the naked eye.)

提交回复
热议问题