开发者

How to determine the transparency color of a bitmap

I know you can programmatically determine the tranparency c开发者_如何转开发olor of a .gif

Is there a way to do the same for a Bitmap?

Right now, I am doing this heuristically by sampling around the outer edge but of course this is not 100% reliable.


I don't believe the BMP file format supports the concept of transparency. My understanding is that if BMP images are used with transparency, it's using an application-defined colour, like RGB(255,0,255) to specify transparent areas.


What you may do is:

  • To sample the occluded image.
  • Apply canny edge detection algorithm to detect outer edges of the object in your bitmap image.
  • You can be approximate, you may also need to tweak a bit to get only the outer edges.
  • Then you can perform an intersection of these 2 samples to get the occluded image, across the bitmap image edges.
  • By now, you will be having 2 images. Make sure the occlusion-extracted image is transparent and on top.
  • Just put the original bitmap beneath the extracted image and you'll achieve transparency with your bitmap image too! :)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜