I'm trying to display splash screen for my WPF application. Based on some condition I have to load one of two images I have created. So i have to use SplashScreen class instead of setting a static image as flashscreen. Which is easy and works in my case.
I'm doing something like following,(I have set the both images as Embedded Resource)
string splashImage = string.Empty;
if (Condition)
{
splashImage = "ApplicationType1.png";
}
else
{
splashImage = "ApplicationType2.png";
}
SplashScreen screen = new SplashScreen(splashImage);
screen.Show(true);
Which gives me exeception,
Cannot locate resource ApplicationType1.png
Finally i figured it out,
Problem was with the .png image i have added. Still i have no clue why it couldn't load that specific image. I just got the .jpg image and it works fine.
And it works with both build actions Embedded Resource or Resource
Related
Loading an embedded resource PNG image into any view works fine, but when i try to load an embedded resource SVG image it wont appear any reasons why !
this code works fine
Image devimage= new Image() { Source = ImageSource.FromResource("DOTFORMS3.Icons.developers.png") };
but this code wont make the svg image appears
Image devimage= new Image() { Source = ImageSource.FromResource("DOTFORMS3.Icons.developers.svg") };
i even tried this code still nathing !
SvgCachedImage devimage= new SvgCachedImage() { Source = ImageSource.FromResource("DOTFORMS3.Icons.developers.svg") };
if you want to load an SVG, use SvgImageSource with SvgCachedImage
I've been trying to get my cursor to be a custom cursor from a .cur file located in a folder in my project as a Resource. Here's my solution layout:
Solution
WPF Application
WPF Class Library
SampleControl.xaml (this is hosted in the WPF Application in the solution)
Images
test_cursor.cur
test_cur.cur's build action is set to Resource. In my class library is a UserControl at the top level which is what I want to change the cursor for. Here's the relative code:
public partial class SampleControl: UserControl
{
InitializeComponent();
StreamResourceInfo streamResource = Application.GetResourceStream(new Uri("test_cursor.cur", UriKind.Relative));
Cursor = new Cursor(streamResource.Stream);
}
I've tried a few different variations of the Uri but I always get an error Cannot locate resource 'test_cursor.cur'.
The file path is wrong.
StreamResourceInfo streamResource = Application.GetResourceStream(new Uri("Images\\test_cursor.cur", UriKind.Relative));
Cursor = new Cursor(streamResource.Stream);
I got it working doing the following:
Uri uri = new Uri("pack://application:,,,/SampleClassLibrary;Component/Images/test_cursor.cur");
StreamResourceInfo streamResource = Application.GetResourceStream(uri);
SampleClassLibrary is the name of the class library project under the solution.
I had to make the Uri the way it was because the .cur file is a Resource under a class library and is being hosted in a different project under the same solution
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 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 have seen this post: Display GIF in a WP7 application with Silverlight
But in my case? for animating I am using a popup. So when application starts it shows a popup for 5 seconds. In this popup I want to show some .gif image, but it doesn't work.
Here is the code which I implement:
public partial class AnimatedSplashScreen : UserControl
{
protected Uri ImageSource
{
get;
set;
}
public AnimatedSplashScreen()
{
InitializeComponent();
ImageSource =
new Uri(
"http://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Sunflower_as_GIF.gif/200px-Sunflower_as_GIF.gif",
UriKind.Absolute);
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
}
And xaml code is:
<UserControl.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Width="480"
Height="800"
Background="White">
<imagetools:AnimatedImage Source="{Binding ImageSource, Converter={StaticResource ImageConverter}}" />
But in result it does't work, it shows an empty background.
Updated:
ImageTools.IO.Decoders.AddDecoder();
ImageSource = new Uri("http://a3.twimg.com/profile_images/1136683647/hisoka_normal.gif", UriKind.Absolute);
It still doesn't work
Finally working... Talk about events conspiring against you... You need to fix all these things first!
(note there is a following problem with only the first 2 frames being animated but that is for another question):
Part 6 (getting sleepy now)
Lastly relative image URLs starting with "/" are not supported by the ImageTools.Controls.ImageConverter, so you need to use a relative URL without the leading "/". I found that once every other problem was fixed I was getting an unsupported exception with the path.
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
InitializeComponent();
this.ImageSource = new Uri("layer1.gif", UriKind.Relative);
this.DataContext = this;
Part 5
You need to set the binding DataContext somewhere.
You do not connect the XAML page DataContext to the code behind object. I could not see where you had done this. A very simple/quick way is to set this.DataContext = this; in the page's constructor.
Part 4
You can only bind to public properties!
Your ImageSource property is currently protected. Change it to Public
public Uri ImageSource
{
get;
set;
}
Part 3
I also note your ImageSource property is not an INotifyPropertyChange type property. So setting it after InitializeComponent will not work.
Try it this way round (or change it to use a notify property):
public AnimatedSplashScreen()
{
ImageSource =
new Uri(
"/200px-Sunflower_as_GIF.gif",
UriKind.Relative);
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
InitializeComponent();
}
Part 2 (actually not support by ImageTools.Controls.ImageConverter)
The cross domain file was apparently only one problem. Based on the comments you also need to store your images on your own website and reference them with an appropriate URI format.
If you put your files in a folder called images under ClientBin you use this format:
"/images/imagename.jpg"
This is the best option as the images also use Browser caching!
For your example it would be like this:
ImageSource =
new Uri(
"/images/200px-Sunflower_as_GIF.gif",
UriKind.Relative);
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
and put the example file in your client bin folder under images.
If you do not use the leading "/" Silverlight assumes the files are resources in the current module instead e.g.
"images/imagename.jpg"
Part 1
This is actually a copyright issue, to stop people deep-linking files from other people's sites without permission.
The Wikimedia.org site does not have any cross domain access files e.g.:
http://upload.wikimedia.org/crossdomain.xml
http://upload.wikimedia.org/crossdomainpolicy.xml
wikimedia.org/crossdomain.xml
wikimedia.org/crossdomainpolicy.xml
... presumably as they do not want others to use the files they host there outside of their own website.
That means Silverlight will not allow access to files on those sites as it is a good Internet citizen. Try hosting the files on your own site (where your Silverlight app resides), then it will not need any cross domain access file at all.
Side note: If you do ever need a cross domain file on a website, for use by Silverlight, use a crossdomainpolicy.xml as the other one is not as useful (designed for older flash use)