Loading BitmapImage into code

From my assembly (A), I want to call a method in another assembly (B) that passes the image. This image is then displayed in the WPF window - the window is part of Project B.

I cannot transfer the ImageSource file with the package: // uri, as this is evaluated in context B, so I think I need to cache the image using CachedBitmap (?) When still in A.

BitmapImage img = new BitmapImage(new Uri("Images/32px-Nuvola_apps_cache.png", UriKind.Relative)); CachedBitmap cbmp = new CachedBitmap(img, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); 

I managed to get this to work if I installed the image in the Embedded Resource and loaded it as a stream, but this is not WPF way.

It seems from the package: the documentation that I should do this, but I tried these below and no one worked;

"Images / 32px-Nuvola_apps_cache.png": "Could not find part of the path" msgstr "URI prefix not recognized." . "pack: // siteoforigin: ,, Images / 32px-Nuvola_apps_cache.png": "The URI prefix is ​​not recognized."

All I want to do is load the .png Resource file into memory and pass it wholesale for the method in another assembly.

Thanks Paul.

+4
wpf bitmapimage
Apr 29 '09 at 10:57
source share
1 answer

Try:

 pack://application:,,,/YourAssemblyName;component/Images/32px-Nuvola_apps_cache.png 
+7
Apr 29 '09 at 11:30 a.m.
source share



All Articles