Silverlight app Image not showing at runtime - image

In Visual Studio 2010 I have created a new project with the Silverlight Business Application template. I added an Images folder under the Assets folder. The png files in this folder have Build Action set to Resource, and Copy To Output Directory set to Always. In the header section I added an <Image Source="Assets\Images\logo.png" /> element. In design time it displays my image. At runtime it does not.
Any idea as to why my image is missing at runtime?
--Shawn

I had a similar problem with images showing in design-time, but not at runtime. Mine was using a pack URI so I wanted to post that fix as well:
Does not work at runtime, does work at design-time:
<Image Source="TelerikDemo;component/Images/logo.png" />
Works at both design and runtime:
<Image Source="/TelerikDemo;component/Images/logo.png" />
Note the extra '/' before the Pack URI starts.

hmf! Turns out my backslashes needed to be forward slashes!

Related

No embedded Image appear in xamarinForm

Iam newbie to XamarinForms and I use visual Studio 2017.
I want to add embeddedImage to my app so to the "imagepage.xaml" file I added:
embeddedImg.Source = ImageSource.FromResource("XFDemo.Images.baby.jpg");
and in "imagepage.xaml.cs" I added:
<Image x:Name="embeddedImg" Aspect="AspectFill" />
but no image appear in the app. just a blank page I can see.
please note that the image exist in PCL project inside "Images" folder and I set the "Action Build" of the image to "Embedded resource".
finally I found the solution ...
thats happened because Iam using xamarin live player and there is some limitations with xamarin live player one of these limitations is embedded resources.
check the following link to see those limitations:
enter link description here

Image is not visible in android project with XAML forms - Xamarin even though provided solutions applied

I tried solutions from the following links but none worked.
where-to-put-images-for-xamarin-froms-application
developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images
image-not-showing-in-xamarin-forms-app.html
I used below syntax
<Image Source="lock.png" HeightRequest="20" WidthRequest="20" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="0" Grid.Column="0"></Image>
Here is the image for where i've kept image
No image displays
Edit
These are the only things in my XAML page.
In my case the issue was of assembly.
when trying all the possible solutions like
1.) Changing Build Action
2.) Adding Image to all the folders within Resources
3.) Naming Convention should not include - in File/Image Name.
4.) Changing Background Color
I also got one solution while searching for embedded Images that assembly was missing here.
This change worked for me in using Local Images.
Got that solution from this link
Right click the lock.png image and see if there is an option "include in project"
If there is, project cannot find image
In my case I need to use method Forms.Init(Context activity, Bundle bundle), in my SplashScreen OnCreate method and Activity class OnCreate method. But it also important that images build action properties is set on AndroidResource.

Wp7 background image not showing up when i debug

I'm new to WP7 programming but have XP with other platforms, I am just running through all the basics so I can get to know the language but I have hit a roadblock I've entered a source for my background image:
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Grid.Background>
</Grid>
And the image shows up as a background in the design tab that is next to the XAML but when I debug and the emulator starts its just a black screen no background image, what have I missed? I have tried other ways of setting a background like:
<Grid x:Name="LayoutRoot">
<Canvas>
<Canvas.Background>
<ImageBrush ImageSource="C:/users/hypernova/pictures/Background1.jpg">
</ImageBrush>
</Canvas.Background>
</Canvas>
</Grid>
but the same thing happens I've tried a few other ways also but again nothing, I'm sure I've missed something I should have caught.
The path
C:/users/hypernova/pictures/Background1.jpg
exists on your dev machine, not on any Windows Phone 7+ device.
Remember, users will be downloading your app from the store, then running it on their phones. How would they possibly access your hard drive and get that image?
Unfortunately, since the design surface allows you to do this, it can of course be confusing to a new developer.
What you should do is add your image to your project as a Resource, then reference the resource via a pack URI (don't click on that link unless you want to scare yourself silly).
To add it as a resource, simply add the image to the root of your WP7 project, right click on it, select Properties, and then change the build action to Resource (not Embedded Resource, mind you).
Next, you have to construct a pack URI for this resource. This is ... not easy. You can use the tools in Visual Studio to do this, by editing the properties of your ImageBrush in the designer. This is the simplest, and recommended, route. All you have to do is edit the ImageSource of your ImageBrush in the Properties tool window, and select the image from the list of available images in the solution.
The other way is to manually construct the pack URI. For example, you could take the following
/[project assembly name];component/Background1.jpg
replace [project assembly name] with the name of your assembly (no extensions), and use it as your ImageSource value. You can find the correct project assembly name by looking at the Assembly Name under the Application section of the project properties.
<ImageBrush ImageSource="/MyWp7Application;component/Background1.jpg"/>
Note, depending on how your project folder structure is constructed, this URI may be different. Constructing the correct URI outside of the tools provided is a task deserving of another question.

Phonegap on WP7 does not load images

I'm starting my first PhoneGap project and am developing using Visual Studio and Windows Phone 7, although I intend on ultimately deploying to iOS and Symbian as well.
However, I'm stuck at Step 1. I have added an image to the www/images folder, and put the following code:
<img src="images/login-btn.png" width="103" height="42" style="margin-left:90px;" />
And I get:
It works fine when I preview it in IE9, but I don't have a Mac to test it on iOS yet.
It's worth noting that the JS files and CSS have loaded fine, it's just any image (whether referenced in CSS or an <img> tag) always comes up broken.
My guess would be the Build Action of your image file is incorrect.
According to http://wiki.phonegap.com/w/page/48672055/Getting%20Started%20with%20PhoneGap%20Windows%20Phone%207#4Reviewtheprojectstructure section 4. You should be setting the Build Action of your images etc to Content which simply copies them into the output project when it is built. They are probably currently set to Resource or None.
To change the Build Action right click a file and choose properties to go to the properties window if you do not already have it open. It is probably then the first property. Just click and choose the correct one.
I'm posting this to questions that I found while trying to find my answer to the same problem. The JS framework I use adds a url query to each image when in a debugging mode (in order to force browsers to reload image, instead of using cached). So, my image "image/background.jpg" would be accessed as "image/background.jpg?d=34342233". But, when running on PhoneGAP for Windows Phone, it won't recognize the image, and thus it shows up as broken. So, I had to turn off debugging for the framework I use, and suddenly the images showed up (still, don't forget to set the Build Action to "Content" as mentioned earlier).

How to use a relative image source in WPF using IronPython

I'm creating a WPF project using Python Tools for Visual Studio (in VS 2010). I add an Image control to the form. I click the "..." in the Image's Source property, and find an image.
This adds an "Images" folder to the project (both in the filesystem and in the solution), and copies the image to that folder (again both in the filesystem and in the solution). The image does not show up in the "Add" dialog. The Source attribute is set to "Images/foo.png".
In the XAML the source is blue-underlined because the "Build Action" is not set to "Resource". The only build actions available are "Content", "Compile", and "None". I presume "Resource" isn't available in a dynamic language like IronPython (certainly an embedded resource would be complex). I don't know whether this is the problem or whether this can be ignored.
The image does not show in the live editing window, and it doesn't show when the program runs.
I've tried "/Images/foo.png" (as suggested here), "pack://application:,,,/foo.png", "pack://application:,,,/Images/foo.png", "pack://siteoforigin:,,,/foo.png", and "pack://siteoforigin:,,,/Images/foo.png".
(The siteoforigin doesn't work because the 'origin' is ipy.exe. If I move the Images folder to the folder where IronPython is installed, then this does work. Obviously not a great solution!).
I've tried moving the Images folder in the filesystem to the same folder as the solution (i.e. one level up in the hierarchy), and having the image in the same folder as the .py file rather than in an Images subfolder.
If I change the source (directly in the XAML) to an absolute path, then it works perfectly. Obviously this isn't a great solution either!
How can I use a relative path for the Image?
It is possible. Apparently all you need to do is specify the source as a BitmapImage and relative URI will use the current directory as the base. Ignore the warnings about the file not being a resource, it doesn't really matter. It will show when you run your program.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyWpfApplication" Height="300" Width="300">
<Grid>
<Image>
<Image.Source>
<BitmapImage UriSource="../Relative/Path/To/Image.png" />
</Image.Source>
</Image>
</Grid>
</Window>
I think it is all due to the default value converters for images. If you bypass using them, it all seems to just work out.
The best way I found to deal with image paths is to just completely bypass that ponderous pack:// URI nonsense and simply use a Binding that binds directly to a BitmapImage.
<Image Source="{Binding imgWarningYellow}" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" />
This way, I can use a simple GetFullPath filesystem call in code to locate the damn thing and load it up as a BitmapImage:
yellowbitmap = System.Windows.Media.Imaging.BitmapImage()
yellowbitmap.BeginInit()
yellowbitmap.UriSource = System.Uri(System.IO.Path.GetFullPath("Images\warning-yellow50.png"))
yellowbitmap.DecodePixelHeight = 50
try:
yellowbitmap.EndInit()
except System.IO.FileNotFoundException as e:
print e.Message
else:
self.imgWarningYellow = yellowbitmap

Resources