xaml - Cannot find the image by providing the relative path in Silverlight -
I am working on a Silverlight application and I have a hard way to set the relative path of an image in my application there is time. / P>
This is a short picture of my project directory:
MyProjectL Image L. Mountain 1 JPG L Sprite Object L Mountain Factor c. El GameScreen XML
Basically, I paint a rectangle by using GameScreen.xaml using an image brush.
& lt; Rectangle name = "rec_bg" horizontal alignment = "left" workspaceElement = "top" width = "800" height = "600" & gt; & Lt; Rectangle.Fill & gt; & Lt; ImageBrush x: name = "ib_bg" image = "./ images / mountain1.jpg" & gt; & Lt; / ImageBrush & gt; & Lt; /Rectangle.Fill> & Lt; / Rectangles & gt;
This xaml code works, that image can be found in the image folder without problems.
I want to change the image dynamically, and in this class I have a mountainfacracker. Cs, I have a method with this code:
imagebrush Brush = new imagebrush (); Bitmap Image Image = New Bitmap Image (New Uri (". / Picture / Mountain" + Level + ".jpg", Urikhind .Relative)); Brush.ImageSource = image;
This method will return an image brush which is applied to re_bg rectangle object. However, this code can not find the specified image.
Does anyone know how to fix this? Thank you.
It depends on how you're embedding the image. I am assuming that you have set it as "content", so it has not been embedded in DLL but embedded in the XAP. In that case, you can use it relative to the project root, so you will use it:
"picture / mountain ..."
(Note, you do not use In front of ./, you are automatically relative to the root of the application). If you have set it as an embedded resource, then you have to take it out of the DLL with the help of the stream - I do not recommend it.
Small story boring: Try to remove the head. / And make sure the properties of the image are in the form of content
Comments
Post a Comment