Здесь приведен код для установки прозрачного фона для любого растрового ресурса в словаре ресурсов (не Resource.resx, часто используемого в возрасте Windows.Forms). Я называю этот метод перед InitializeComponent () - методу. Методы «ConvertBitmap (источник битмапа)» и «BitmapFromSource» (битмапсурс источника BitmapSource) упоминаются в сообщении от melvas выше.
private void SetBitmapResourcesTransparent()
{
Image img;
BitmapSource bmpSource;
System.Drawing.Bitmap bmp;
foreach (ResourceDictionary resdict in Application.Current.Resources.MergedDictionaries)
{
foreach (DictionaryEntry dictEntry in resdict)
{
// search for bitmap resource
if ((img = dictEntry.Value as Image) is Image
&& (bmpSource = img.Source as BitmapSource) is BitmapSource
&& (bmp = BitmapFromSource(bmpSource)) != null)
{
// make bitmap transparent and assign it back to ressource
bmp.MakeTransparent(System.Drawing.Color.Magenta);
bmpSource = ConvertBitmap(bmp);
img.Source = bmpSource;
}
}
}
}