I want to put an image on a button, but I want part of the image to be transparent. How do I do this?
Try the Image.OpacityMask
property. You can give it a brush that specifies the region you want to be transparent.
EDIT: From MSDN:
There is no direct support for color-keying a bitmap in WPF. However, it is fairly easy to implement on your own. Dwayne has implemented a ColorKeyBitmap on his blog: http://blogs.msdn.com/dwayneneed/archive/2008/06/20/implementing-a-custom-bitmapsource.aspx I believe it links to the code on Codeplex as well. You could also accomplish this simply by reading your bitmap into system memory, iterating through all the pixels and setting their values yourself, and constructing a new bitmap out of that array.
Use a paint program (I use Paint.Net) to change the area you want transparent to an alha=0 color. Then save the image (mine was JPG) as a PNG. Seemed to work fine for me in the WPF Image control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With