BitmapSource from embedded image
You can create a BitmapImage from the stream by setting its StreamSource
property:
public BitmapSource GetSourceForOnRender(){ var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var bitmap = new BitmapImage(); using (var stream = assembly.GetManifestResourceStream("KisserConsole.someImage.png")) { bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); } return bitmap; }
That said, you would usually create a BitmapImage from a Resource File Pack URI, like e.g.
new BitmapImage(new Uri( "pack://application:,,,/KisserConsole.someImage.png"));
You can try to use this:
Uri uri = new Uri( $"pack://application:,,,/YourAssemblyName;component/Resources/images/photo.png", UriKind.Absolute );BitmapImage bitmap = new BitmapImage( uri );
Make sure the Build Action of the image file is set to Resource.