locked
How to set image from pictures library? RRS feed

  • Question

  • I have a image control and I want to set the source to be from the "pictures". How to ad it.

    Any help will be Appreciated.

    Tuesday, May 14, 2013 3:58 PM

Answers

  • Have a look at this sample too

    Image Source from Pictures Library Dynamically C#

    Remember to get permission to access Pictures Library


    pradeep aj If it answers, then please Mark it as Answer

    • Marked as answer by Mayura R Tuesday, May 14, 2013 4:37 PM
    Tuesday, May 14, 2013 4:01 PM
  • This code will be helpful to you

    private async void GetPicture_FromPicLib()
            {
                StorageFolder folder = KnownFolders.PicturesLibrary;
                StorageFile file =await folder.GetFileAsync("test1.jpg");
    
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
                BitmapImage img = new BitmapImage();
                img.SetSource(stream);
                this.imgControl.Source = img;
            }

    imgControl is the Name of the Image control

    test1.jpg is the image


    pradeep aj If it answers, then please Mark it as Answer

    • Proposed as answer by Pradeep AJ Tuesday, May 14, 2013 4:06 PM
    • Marked as answer by Mayura R Tuesday, May 14, 2013 4:37 PM
    Tuesday, May 14, 2013 4:00 PM
  • To implement this in MVVM Architecture, you can refer this 

    http://lunarfrog.com/blog/2012/11/21/image-file-binding/


    pradeep aj If it answers, then please Mark it as Answer


    • Edited by Pradeep AJ Tuesday, May 14, 2013 4:05 PM
    • Marked as answer by Mayura R Tuesday, May 14, 2013 4:37 PM
    Tuesday, May 14, 2013 4:05 PM

All replies

  • This code will be helpful to you

    private async void GetPicture_FromPicLib()
            {
                StorageFolder folder = KnownFolders.PicturesLibrary;
                StorageFile file =await folder.GetFileAsync("test1.jpg");
    
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
                BitmapImage img = new BitmapImage();
                img.SetSource(stream);
                this.imgControl.Source = img;
            }

    imgControl is the Name of the Image control

    test1.jpg is the image


    pradeep aj If it answers, then please Mark it as Answer

    • Proposed as answer by Pradeep AJ Tuesday, May 14, 2013 4:06 PM
    • Marked as answer by Mayura R Tuesday, May 14, 2013 4:37 PM
    Tuesday, May 14, 2013 4:00 PM
  • Have a look at this sample too

    Image Source from Pictures Library Dynamically C#

    Remember to get permission to access Pictures Library


    pradeep aj If it answers, then please Mark it as Answer

    • Marked as answer by Mayura R Tuesday, May 14, 2013 4:37 PM
    Tuesday, May 14, 2013 4:01 PM
  • To implement this in MVVM Architecture, you can refer this 

    http://lunarfrog.com/blog/2012/11/21/image-file-binding/


    pradeep aj If it answers, then please Mark it as Answer


    • Edited by Pradeep AJ Tuesday, May 14, 2013 4:05 PM
    • Marked as answer by Mayura R Tuesday, May 14, 2013 4:37 PM
    Tuesday, May 14, 2013 4:05 PM