I created a user control, which is made with images.
I tried to modify them by C# method, for example:
imgElement.Source = new BitmapImage(new Uri("ms:appx/Resources/IconElement/my_icon_element.png"));
imgBackgroundElement.ImageSource = new BitmapImage(new Uri("ms:appx/Resources/BackgroundElement/my_background_element.png"));
The soft finds images but doesn't show them ; the image control is empty.
If do not use the method and let images by default, they are shown...
Can anyone teach me why ? ^^
Thanks !
An absolute path for your image will be:
ms-appx:///Resources/IconElement/my_icon_element.png
Related
I have a List where the string is the url of an image.
I am trying to dynamically create a grid of images with the source being each url.
I have tried binding but it doesn't seem to work. I also cannot access the x:Name of an image I created in Xaml. I am open to doing this in Xaml or in the code behind.
Any ideas of how to do this.
//imageList is a List<string> with your image urls in it
foreach(var i in imageList) {
Image image = new Image();
image.Source = ImageSource.FromUri(new Uri(i));
// you will need to add logic to calculate the Row/Column for each image
myGrid.Children.Add(image,x,y);
}
I'm looking for a method to make all my resource files work properly after I have written my project in a cd.
For example I have saved my images in Project Name\Project Name\obj\Debug\Images and I want them to be usable both in xaml and regular c# code, when I insert that cd in another machine.
Thanks for your time!
What worked for me was, using the Image class for both backgrounds and overlapping images.
In xaml the code is <Image x:Name="Image1" Source="..\obj\Debug\Images\image.jpg"/>
and you initialise it in c# using
public PageName()
{
InitializeComponent();
Image1.Source = new BitmapImage(new Uri(#"../Images/cafeteria.jpg", UriKind.Relative));
}
It's a shame because (atleast in my case) the ImageBrush Class didn't support relative uris for some reason..
I am working with a Windows Forms application in Visual Studio 2010. I have a resources file, Flags.resx. I have uploaded images to the resource file, and want to show them in an Image control (picFlag). What is funny is THIS is super-easy, because my image files are strongly typed:
picFlag.Image = Flags.AE_Flag
But what I want to do, of course, is not. I want to dynamically provide the name of the image like this pseudo-code:
string strFlag = "AE_Flag";
picFlag.Image = Flags[strFlag]
Any suggestions on the simplest way to do this?
you can use the following
var rm = new System.Resources.ResourceManager("YourProject.Properties.Resources",
typeof(Resources).Assembly);
var image = rm.GetObject("AE_Flag") as System.Drawing.Image;
hope it will help you
I want to access some images in my Windows Phone class library, but how can I access these images?
I have a method which will set the image, but
new Uri("/Assets/Images/MyImage.png", UriKind.Relative);
doesn't work. I've tried setting the image to Resource instead of Content, but it also doesn't work.
So how can I provice images in my class library?
From what I gather it looks like you are trying to set the source of an image from the XAML code behind file.
If so you can do so as follows:
MyImage.Source = new BitmapImage(new Uri("/Assets/Images/MyImage.png", UriKind.Relative));
Hope this helps.
I am looking for ways to save the output of a Chart control as an image on the hard drive. Is it possible in SL? as I am not sure so thought of putting a question here..
Thanks...
have a look here: Can I programmatically capture snapshot of a Silverlight User Control?
You can simply take a screenshot of your chart. If you want to put in on the HD with silverlight you need to open a SaveFileDialog. Then it is possible.
EDIT: If you want to save it in different formats use ImageTools. http://imagetools.codeplex.com/. If you use ImageTools you can get a stream like this:
var editBitmap = new WriteableBitmap(1024, 786);
editBitmap = new WriteableBitmap((int)(this.RenderSize.Width), (int)(this.RenderSize.Height));
editBitmap.Render(this, new MatrixTransform());
editBitmap.Invalidate();
var myImage = editBitmap.ToImage();
Stream stream = myImage.ToStreamByExtension("png");
Hope this helps.
BR,
TJ