How can I load a BitmapSource
from an image file?
BitmapImage
class is a non-asbtract
subclass of BitmapSource
, so just use the new BitmapImage(Uri)
constructor and pass that new instance to anything that expects a BitmapSource
object.System.Uri
: a Uri
isn't just for http://
addresses, but it's also suitable for local filesystem paths and UNC shares, and more.So this works for me:
BitmapImage thisIsABitmapImage = new BitmapImage(new Uri("c:\\image.bmp")); BitmapSource thisIsABitmapImageUpcastToBitmapSource = thisIsABitmapImage;
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