473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to load a Image on ImageBox in Silverlight after browsing

Hi All,
I have a Image box and a button named Browse below ImageBox on my form.
When the User Clicks on the Browse button it should open Dialog and display images.
Below is my code.
Expand|Select|Wrap|Line Numbers
  1.  
  2. private void btnBrowse_Click(objectsender,RoutedEventArgs e)
  3.  {
  4.   OpenFileDialog imageDialog =new OpenFileDialog();
  5.   //Filter default filetype to be allowed for selection 
  6.  
  7.   imageDialog.Filter = "Pictures (*.jpg)|*.jpg";
  8.   imageDialog.FilterIndex = 1;
  9.  
  10.   //Allows multiple files to be selected 
  11.   imageDialog.Multiselect = true;
  12.  
  13.   //Call the ShowDialog method to show the dialog box 
  14.   bool? userClickedOK = imageDialog.ShowDialog();
  15.  
  16.   //Process input if the user clicked OK 
  17.  
  18.   if (userClickedOK == true)
  19.   {
  20.         image1.Source= ;
  21.   }
  22. }
  23.  
My issue is how should i get the Image in image1.Source.
Expand|Select|Wrap|Line Numbers
  1.             if (userClickedOK == true)
  2.             {
  3.  
  4.                 image1.Source= ;
  5.  
  6.             }
  7.  
Please help me in above Code,how should i use ImageDialog object to get the Image in Image1 imagebox.
Aug 23 '11 #1

✓ answered by SEhtesham

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.

Expand|Select|Wrap|Line Numbers
  1. OpenFileDialog objFileDialog = new OpenFileDialog();
  2.             bool? IsSelected = objFileDialog.ShowDialog();
  3.  
  4.             if (IsSelected == true)
  5.             {
  6.                 BitmapImage bitImage = new BitmapImage();
  7.                 bitImage.SetSource(objFileDialog.File.OpenRead());
  8.  
  9.                 //Image1 is object of Image
  10.                 Image1.Source = bitImage;
  11.             }

1 3369
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.

Expand|Select|Wrap|Line Numbers
  1. OpenFileDialog objFileDialog = new OpenFileDialog();
  2.             bool? IsSelected = objFileDialog.ShowDialog();
  3.  
  4.             if (IsSelected == true)
  5.             {
  6.                 BitmapImage bitImage = new BitmapImage();
  7.                 bitImage.SetSource(objFileDialog.File.OpenRead());
  8.  
  9.                 //Image1 is object of Image
  10.                 Image1.Source = bitImage;
  11.             }
Aug 25 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Manny Chohan | last post by:
HI Guys, I need to load image in table cell from codebehind. i have the following code: TableRow tRow = new TableRow(); Table2.Rows.Add(tRow); TableCell tCell1= new TableCell(); if...
4
by: Scott Meddows | last post by:
I want to load a multipage TIFF image into memory as an Image object but I read that the FromFile method locks the file. Can I load this into a stream, close the physical file then manipulate the...
2
by: Beruang | last post by:
Hi, How to load image from database MS SQL Server into PictureBox if I have Table called Student(StudID, Name, StudImage) StudImage data types is Image. Thanks
6
by: nuhura01 | last post by:
Hi all... My system contains an image which I have saved it at client side. Unfortunately, when users want to view the image, the image doesn't loaded. If i'm not mistaken, it is set at the HTML...
11
by: Chamnap | last post by:
Hello, I have several images that need to be loaded dynamically based on user interaction. Each image size is about 6000x1500 pixels. I see several sites they make the image blur, blur, blur,...
1
by: hamzeh83 | last post by:
hi all, i want load image runtime on crystal report (Windos form) Thanxx
2
by: saadkhan | last post by:
How can i load image in <asp:image....> tag? I`v made coded in both the event of pageload to define imageurl and as well as in imageload event....but nothing is working. Plz help me!
2
by: abcomp01 | last post by:
how to load image and display in flash from http post? i would to http post some website and return captcha something and display captcha from response some website from using actionscript...
6
by: ghjk | last post by:
I store images using one of my web pages. Next I want to load image from the db and pass the value to ajax page. Other values got correctly. But didn't get image.This is my code. php page. When...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.