×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    How to load recent images from the media library?

    Here is my class to get recent photos from media library..

    Code:
       public class RecentPhoto
        {
            public string FilePath { get; private set; }
    
            public BitmapImage Thumbnail
            {
                get
                {
                    var width = 226.0 * (Application.Current.Host.Content.ScaleFactor / 100.0);
    
                    return new BitmapImage(new Uri(FilePath, UriKind.Relative)) { DecodePixelWidth = (int)width };
                }
            }
    
            public RecentPhoto(string file)
            {
                FilePath = file;
            }
        }
    
        public class RecentPhotos
        {
            public static List<string> GetPaths()
            {
                List<string> ImagePaths = new List<string>();
    
                using (MediaLibrary library = new MediaLibrary())
                {
                    foreach (var item in library.Pictures.Reverse().Take(3))
                    {
                        ImagePaths.Add(item.GetPath());
                    }
                }
    
                return ImagePaths;
            }
    
            public RecentPhoto Photo1 { get; private set; }
            public RecentPhoto Photo2 { get; private set; }
            public RecentPhoto Photo3 { get; private set; }
    
            public void Initialize()
            {
                var path = RecentPhotos.GetPaths();
    
                if (path.Count > 0)
                {
                    Photo1 = new RecentPhoto(path[0]);
                    Photo2 = new RecentPhoto(path[1]);
                    Photo3 = new RecentPhoto(path[2]);
                }
            }
        }
    Here is my project, any answer will be highly appreciated!

    Thank you
    Last edited by venu238; 2014-04-14 at 19:56.
    Clipr: Best ever image clipping tool and first of it's kind in windows phone!!

    Download here
    http://www.windowsphone.com/s?appid=d533f018-238a-429c-affc-55a46c2dc69f

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    475

    Re: How to load recent images from the media library?

    Hi.
    your problem is?
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  3. #3
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: How to load recent images from the media library?

    There is no exception, but images are not loading!
    Clipr: Best ever image clipping tool and first of it's kind in windows phone!!

    Download here
    http://www.windowsphone.com/s?appid=d533f018-238a-429c-affc-55a46c2dc69f

  4. #4
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: How to load recent images from the media library?

    Solved it!
    Clipr: Best ever image clipping tool and first of it's kind in windows phone!!

    Download here
    http://www.windowsphone.com/s?appid=d533f018-238a-429c-affc-55a46c2dc69f

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    523

    Re: How to load recent images from the media library?

    What caused the issue? Might be interesting to see how you adapted the code if someone else runs into the same problem.

  6. #6
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: How to load recent images from the media library?

    Instead of loading image paths I've directly loaded images. It's working fine with 3 or 4 images but if I load more than 4 then app is force closing.

    Here is the class

    Code:
        public class RecentPhoto
        {
            public ImageSource Thumbnail { get; private set; }
    
    
            public RecentPhoto(ImageSource file)
            {
                Thumbnail = file;
            }
        }
    
        public class RecentPhotos
        {
            public static List<Image> GetPaths()
            {
                List<Image> ImagePaths = new List<Image>();
    
                using (MediaLibrary library = new MediaLibrary())
                {
                    foreach (var item in library.Pictures.Reverse().Take(18))
                    {
    
                        Stream imageStream = item.GetImage();
                        var imageToShow = new Image()
                        {
                            Source = PictureDecoder.DecodeJpeg(item.GetImage())
                        };
                        ImagePaths.Add(imageToShow);
                        
                    }
                }
                return ImagePaths;
            }
    
            public RecentPhoto Photo1 { get; private set; }
            public RecentPhoto Photo2 { get; private set; }
            public RecentPhoto Photo3 { get; private set; }
    
            public void Initialize()
            {
                var path = RecentPhotos.GetPaths();
    
                Photo1 = new RecentPhoto(path[0].Source);
                Photo2 = new RecentPhoto(path[1].Source);
                Photo3 = new RecentPhoto(path[2].Source);
            }
    Is there any other way to load images?
    Clipr: Best ever image clipping tool and first of it's kind in windows phone!!

    Download here
    http://www.windowsphone.com/s?appid=d533f018-238a-429c-affc-55a46c2dc69f

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: How to load recent images from the media library?

    Based on the description, it seems like an out-of-memory situation. Are you resizing the images somewhere? Remember that decoded images can be large, regardless of the file size (because that is compressed).

  8. #8
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: How to load recent images from the media library?

    Nope, how should and where should I resize image?
    Should I convert ImageSource to bitmapImage and then decode pixel width?
    Clipr: Best ever image clipping tool and first of it's kind in windows phone!!

    Download here
    http://www.windowsphone.com/s?appid=d533f018-238a-429c-affc-55a46c2dc69f

  9. #9
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    523

    Re: How to load recent images from the media library?

    You are getting the stream twice in this example - it should perhaps look like this.
    Code:
    Stream imageStream = item.GetImage();
                        var imageToShow = new Image()
                        {
                            Source = PictureDecoder.DecodeJpeg(imageStream)
                        };
                        ImagePaths.Add(imageToShow);
    Aside from that - you should load the image from the stream using a DecodePixelWidth if you only want to use them as thumbnails for now. Also the Streams aren't disposed so they will keep hogging resources which you probably don't need them to do after you finished loading the thumbnail.

  10. #10
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: How to load recent images from the media library?

    Okay! I want a link to the image source on image tap. So, I should include one more property in my class to get the link of image source.
    Instead of doing all these things, Can I use storage file in the above scenario?

    Edit: Here is how I'm trying t..

    Code:
    List<string> paths = new List<string>();
    using (MediaLibrary library = new MediaLibrary())
    {
         foreach (var item in library.Pictures.Reverse().Take(18))
         {
              paths.Add(item.GetPath());
         }
    }
    
    StorageFile file = await StorageFile.GetFileFromPathAsync(paths[0]);
    By above method I'm not getting the media library element as storage file ..
    Last edited by venu238; 2014-04-15 at 14:48.
    Clipr: Best ever image clipping tool and first of it's kind in windows phone!!

    Download here
    http://www.windowsphone.com/s?appid=d533f018-238a-429c-affc-55a46c2dc69f

Similar Threads

  1. How to save png to media library?
    By venu238 in forum Windows Phone Imaging
    Replies: 7
    Last Post: 2014-03-08, 15:54
  2. Load images from library to empty movie clip
    By elminator in forum [Archived] Flash Lite on Nokia Devices
    Replies: 7
    Last Post: 2011-04-21, 07:55
  3. Dll library load error -46
    By komicek in forum Symbian
    Replies: 2
    Last Post: 2008-06-21, 09:16
  4. failed to load library
    By felixksp in forum Symbian
    Replies: 15
    Last Post: 2007-07-23, 20:19
  5. External Media Library
    By desijatt in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-09-27, 00:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×