×

Discussion Board

Results 1 to 10 of 10

Hybrid View

  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
    Oslo, Norway
    Posts
    28,751

    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).

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
  •  
×