(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .

Forums

Search in:

Go

How to Load image in Imagebox on click event of the button after browsing

  • EhteshamSiddiqui
    EhteshamSiddiqui
    0 points
    0 posts
    Aug 23, 2011, 01:06 PM
        Report Abuse

    Hi,

    My application is in Silverlight,coded in C#.Net in VS2010.

    I have a form with a Imagebox and a Browse button below it.

    My requirement is when the user clicks on Browse button OpenDialog should be opened and the User should be able to click and select an Image file and when the User selects an Image file than that selected Image should be loaded to the Imagebox.

    I have written some code but just facing the problem of Providing the Source to Imagebox.

    Below is my Code

    01.OpenFileDialog imageDialog = new OpenFileDialog();
    02. 
    03.           //Filter default filetype to be allowed for selection
    04.          .Filter = "Pictures (*.jpg)|*.jpg";
    05.           imageDialog.FilterIndex = 1;
    06. 
    07.           //Allows multiple files to be selected
    08.           imageDialog.Multiselect = true;
    09. 
    10.           //Call the ShowDialog method to show the dialog box
    11.           bool? userClickedOK = imageDialog.ShowDialog();
    12. 
    13.           //Process input if the user clicked OK
    14. 
    15.           if (userClickedOK == true)
    16.           {
    17.             image1.Source =
    18.           }
    Please help in the above Code



    Reply

All Posts

  • ppopadiyn
    Pencho Popadiyn
    591 points
    17 posts
    Aug 31, 2011, 10:08 AM
            Report Abuse

    Hello EhteshamSiddiqui,

    You could try this one:

    OpenFileDialog imageDialog = new OpenFileDialog
    {
        Filter = "Pictures (*.jpg)|*.jpg",
        FilterIndex = 1,
        Multiselect = true
    };
     
    bool? userClickedOk = imageDialog.ShowDialog();
    if ( userClickedOk.Value == false )
    {
        return;
    }
     
    BitmapSource bitmapSource = new BitmapImage();
    bitmapSource.SetSource( imageDialog.File.OpenRead() );
    image1.Source = bitmapSource;

    Basically, you need to create a new instance of the BitmapSource class and initialize it via the SetSource property. Then the bitmap source is set to the Source property of the Image.

     

     

     

    Reply
Page  

To reply to this thread you must Log In to your account


Thread


Tags: 
silverlight4
  • Asked
    487 days ago
  • Viewed
    713
  • Last Activity

Related Threads


Shortcuts