954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to load a Image on ImageBox in c#.Net after clicking browse button

Hi,
My application is in VS2010,Silverlight and coded in C#.Net.
My requirement is i want to upload Image in my Imagebox control.As there is no PictureBox control in Silverlight im using ImageBox.
I have a Imagebox,below that a Browse button.
When the User clicks on Browse button,Dialogbox should open and when the USer selects a Image it should be loaded to Image box..
Example for Picturebox is available on the forum but i want it for Imagebox.
Below is my code.

OpenFileDialog imageDialog = new OpenFileDialog();

            //Filter default filetype to be allowed for selection 
            imageDialog.Filter = "Pictures (*.jpg)|*.jpg";
            imageDialog.FilterIndex = 1;

            //Allows multiple files to be selected 
            imageDialog.Multiselect = true;

            //Call the ShowDialog method to show the dialog box 
            bool? userClickedOK = imageDialog.ShowDialog();

            //Process input if the user clicked OK 

            if (userClickedOK == true)
            {
              image1.Source = 
            }

image1 is my image control
Please correct me in image1.Source=.....

Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

I don't know of any ImageBox in C#.
Only a PictureBox control with an Image property.
To load an image in a picturebox use something like:
pictureBox1.Image = MyJPEGimage;

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

im Using Silverlight.I have tried Picturebox in normal windows application.
But there is no Picturebox in silverlight application on Imagebox is there.

Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

imageDialog is the object of OpenFileDialog and i was assigning this object to Image Source.

We will have to bind image to Image.Source. Below is the code snippet I tried and able to bind image.

OpenFileDialog objFileDialog = new OpenFileDialog();
            bool? IsSelected = objFileDialog.ShowDialog();
 
            if (IsSelected == true)
            {
                BitmapImage bitImage = new BitmapImage();
                bitImage.SetSource(objFileDialog.File.OpenRead());
 
                //Image1 is object of Image
                Image1.Source = bitImage;
            }
Ehtesham Siddiq
Junior Poster in Training
59 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: