BitmapSource from file

How can I load a BitmapSource from an image file?

Answers


This works for me:

BitmapSource bSource = new BitmapImage(new Uri("c:\\image.bmp"));
BitmapImage bImage = new BitmapImage(new Uri("c:\\image.bmp"));

You can read the bytes of the image from disk into a byte array and then create your BitmapImage object.

var stream = new MemoryStream(imageBytes);
var img = new System.Windows.Media.Imaging.BitmapImage();

img.BeginInit();
img.StreamSource = stream;
img.EndInit();

return img;

The code follows:

FileStream fileStream = 
    new FileStream(fileName, FileMode.Open, FileAccess.Read);

var img = new System.Windows.Media.Imaging.BitmapImage();
img.BeginInit();
img.StreamSource = fileStream;
img.EndInit();

Need Your Help

What is "pkg-resources==0.0.0" in output of pip freeze command

python python-3.x pip ubuntu-16.04

When I run pip freeze I see (among other expected packages) pkg-resources==0.0.0. I have seen a few posts mentioning this package (including this one), but none explaining what it is, or why it is

Send PHP HTML mail with attachments

php html email attachment

I got a problem: Until today, I sent HTML mails with PHP using a header which contains