开发者

Programmatically draw a (drop)shadow

开发者 https://www.devze.com 2023-03-22 03:19 出处:网络
This probably goes for all programming languages. I use Adobe Flash AS3 and for some reason that is boyond this post, I cannot use built-in dropshadow filters.

This probably goes for all programming languages.

I use Adobe Flash AS3 and for some reason that is boyond this post, I cannot use built-in dropshadow filters.

I do, however, have bitmap data available, with color and alpha values.

So there should be a way to draw my own dropshadow filter.... right? Any good existing algorithms I should go and check out?

Not specifically looking for an AS3开发者_如何学Python implementation, any other example will probably allow me to convert the code.


Usually, dropshadows are done like so:

  • copy your bitmap's alpha channel
  • blur the copied alpha channel (a gaussian blur should be fine)
  • move the copied alpha channel down and to the right
  • use the copied alpha channel to darken the background (that is, multiply the background's RGB values by the inverse value from the alpha channel; this is the same as combining the alpha channel with an all-black bitmap and alpha-blending that over the background)
  • draw the original bitmap (also using alpha-blending)
0

精彩评论

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