开发者

Is there a technique for re anti-aliasing an image to a different background color?

Is there a programmatic approach for drawing an anti-aliased image on a new background color / pa开发者_如何学Cttern that would re-anti-alias the image to the new background color? Preferably accessible to a .Net program?


You can use WPF to create the new image and save it out to an image file.


If an image has already been anti-aliased against a particular background colour then removing this anti-aliasing automatically will prove difficult in code - your best bet is to manually edit the image, unfortunately.


There is no way to do it in the general case. But if you limit your requirements a bit, it can be done.

I can tell you how to do it if we assume the anti-aliased image is of a solid color known to us, and we have the background as a separate file.

For example let's say the anti-aliased image consists of a word in some font, in black. And the background is arbitrary. Then, to "re-antialias" the image for another background, you need two steps:

  1. Recover the original anti-aliased image, isolated from the background. To do this, perform this algorithm:

    for_every_pixel {
    isolated_pixel_intensity = 1 - rgb_distance(mixed_pixel_rgb - background_pixel_rgb, foreground_solid_rgb)
    }
    // rgb_distance is implemented as Pythagora's Theorem in 3D.

  2. Now that you have the foreground image, simply blend it with your new background.

You'd have to write the code yourself. You can use System.Drawing.Bitmap as a basis since you're using .NET.

Edit: Disregard this. It can't actually work, because there are cases that are impossible to solve - namely, when the background image contains areas of the same color as the foreground.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜