FormatConvertedBitmap URI issue
-
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".
Image myImage = new Image();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.
Image myImage2 = new Image();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.
All Replies
-
Wednesday, April 23, 2008 9:35 PMModerator
Hi Matthew,
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 SnippetImage myImage2 = new Image();
myImage2.Source = new FormatConvertedBitmap(
new BitmapImage(
new Uri("pack://application:,,,/Resources/blue.png", UriKind.Absolute)),
PixelFormats.Gray32Float, null, 0);
Hope this helps,
Matt
-
Thursday, March 12, 2009 3:37 PMI posted this as a bug on the Microsoft Connect forum. The pack:// workaround is fine for now.
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=422916

