开发者

Bitmap.MakeTransparent in Silverlight?

How can I make all of the white pixels of a BitmapImage transparent in Sivlerlight?

This is what you do using a regu开发者_开发技巧lar Bitmap:

//Bitmap with a White background:
var bmp = new Bitmap(100, 100);
using (var g = Graphics.FromImage(bmp)){
    g.Clear(Color.White);
    g.DrawString("String", new Font(FontFamily.GenericSerif,10.0f), new SolidBrush(Color.Red), 30, 30);
}

//I want to make White transparent like Bitmap.MakeTransparent does:
bmp.MakeTransparent(Color.White);

In Silverlight, how do I do something like this?:

var bmp = new BitmapImage(new Uri("http://www.google.com/images/logos/ps_logo2.png"));
bmp.MakeTransparent(Color.White);

I'm new to Silverlight, but I expect to be drawing this to a canvas or something later, so it can be a Shader or something like that if it needs to be.


A shader is perfect if you need the effect to be applied again and again but there are more options:

  1. Preproces the image in your favorite paint program. (Fastest, less flexible)
  2. Preproces the image by using a WriteableBitmap. (Slowest, more flexible)
  3. Use a shader. (Fast, very flexible)

For shaders look at this wonderful tool Shazzam

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜