Reputation: 43311
public MainWindow()
{
InitializeComponent();
BitmapImage b = new BitmapImage(new Uri("Images/SampleImage.png", UriKind.Relative));
//PixelFormat f = b.Format; // throws DirectoryNotFoundException
image.Source = b;
PixelFormat f = b.Format; // OK
}
PixelFormat
property throws exception, if called before the line image.Source = b;
. But it succeeds, if called after this line. Why this happens? And want can I do, if I don't want to set this bitmap as image.Source
, only want to work with this object in the program?
Visual Studio 2012,Windows 8, C# WPF project. Images/SampleImage.png is resource file, it is shown in the Image control.
Upvotes: 0
Views: 127
Reputation: 7409
This works
BitmapImage b = new BitmapImage(new Uri("pack://application:,,,/YourApplicationName;component/Images/SampleImage.png"));
PixelFormat f = b.Format;
Upvotes: 1