Wednesday, April 23, 2008 8:55 PM
The following code gets"/Resource/blue.png" out of my assembly where the build action on that file is set to "Resource".
myImage.Source =new BitmapImage( new Uri("/Resources/blue.png", UriKind.Relative));
The code below does *not* work as I would expect, it throws the following exception:
"System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\Resources\blue.png'."
Only if I copy "blue.png" to that directory will it get the image and grayscale it.
myImage2.Source =new FormatConvertedBitmap( new BitmapImage( new Uri("/Resources/blue.png", UriKind.Relative)), PixelFormats.Gray32Float, null, 0);
Why does this URI in the first example reference the resource in the assembly, but the URI in the second tries to reference the image from the file system? I need to second example to read the image out of the assembly.
Wednesday, April 23, 2008 9:35 PMModerator
What you've hit here is most likely caused by resource loading code written by two different developers. One of them knew to resolve as an application reference, and the other didn't. I'll dig deeper to see if I can file a bug to make these APIs more usable. For now, here's how you can do the 2nd code snippet without a problem:Code Snippet
Image myImage2 = new Image();
myImage2.Source = new FormatConvertedBitmap(
new Uri("pack://application:,,,/Resources/blue.png", UriKind.Absolute)),
PixelFormats.Gray32Float, null, 0);
Hope this helps,
Thursday, March 12, 2009 3:37 PMI posted this as a bug on the Microsoft Connect forum. The pack:// workaround is fine for now.