Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a few pictures which is stored in my "image folder". I'm trying to load an image using WPF Browser Application. I have a button and an image box. When I press the button, the image will be displayed in the automatically in the image box.

I was told that I need to insert my image in the Resources file. Is it necessary to do that? Or is there a way to load an image directly from the file to my image box?

I inserted an image in the Resources file. And this is my code.....

C#
public Page1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
           Image i = new Image();
           BitmapImage src = new BitmapImage();
           src.BeginInit();
           src.UriSource = new Uri("book1.png", UriKind.Relative);
           src.CacheOption = BitmapCacheOption.OnLoad;

           image1.Source = src;
           image1.Stretch = Stretch.Uniform;

        }


I don't have any errors, but when i press the button, no image appeared in my image box. How do I load up my image in the image box?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Feb-14 23:15pm    
It looks like you don't have clear distinction between run-time environment and the source code. What should be the source of your image data, resource embedded in the executable module, of files in the file system? In your code, you are trying to load a file from file system, who knows what directory. You need to write correct URI of the file...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900