Convert BitmapImage to System.Windows.Media.Brush

How to convert BitmapImage to System.Windows.Media.Brush ?

I have a BitmapImage, figuratively called bitmap , and I have a Canvas (also figuratively named) canvas .

How to set canvas value to bitmap value?

I tried canvas.Background = bitmap; but this did not work: image.Source = bitmap; works for images but not canvas: and

ImageSourceConverter imgs = new ImageSourceConverter(); canvas.SetValue(Image.SourceProperty, imgs.ConvertFromString(bitmap.ToString()));

didn't work either.

All this worked with images.

Maybe something with bitmap.ToString() will work?

+6
source share
1 answer

Create an ImageBrush and use this as a background:

  ImageBrush ib = new ImageBrush(); ib.ImageSource = bitmap; canvas.Background = ib; 
+14
source

Source: https://habr.com/ru/post/888490/


All Articles