1

i wonder, how i could figure out if an image has a transparency effect applied. Is there any way in JavaScript or HTML5? I have a Base64-coded image. Is there a way to read out the transparency-information (alpha-channel). For example, if i load a PNG-Image, then convert it to base64, then drop it to html5-canvas, now how can i know if this has transparency-effect activated? thanx alot okyo

4

1 回答 1

0

当您说“将其放到 html5-canvas”时,我假设您的意思是使用带有“数据:”URI 方案的图像元素。另外,假设您不想编写 javascript 代码来解析图像文件。

你可以做这样的伪代码:

create 2 off-screen canvases
color one opaque white and the other opaque black
draw the image on both of them
call getImageData on each canvas, using the image bounds
compare the image data

如果图像有任何透明或部分透明的像素,那么大概这两个画布最终会至少有一点不同。一个例外是,如果图像启用了透明度功能,但无论如何都是完全不透明的。另一种情况是,如果非不透明像素只是非常轻微透明 - 不足以改变白色或黑色背景。但这种技术可以捕捉透明度明显的图像。

于 2011-12-12T01:53:19.520 回答