locked
Grid Application Image set to Picture library not rendering images RRS feed

  • Question

  • Hi 

    i have set the windows image library to sampledatasouce.cs by following method. picture name , path all are rendering as expected but image not display (gray image loading). I have debugged the code it is geting right path of the machine wonder why image is not rendering in grouped grid app

    private async void LoadImage()
            {
                try
                {
                    IReadOnlyList<Windows.Storage.StorageFile> resultsLibrary =
                        await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();



                    var group4 = new SampleDataGroup("Group-4",
                                   "Pictures",
                                   "Group Subtitle: 1",
                                   "Assets/DarkGray.png",
                                   "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");



                    foreach (var item in resultsLibrary)
                    {

                        group4.Items.Add(new SampleDataItem(item.DisplayName + "Group-1",
                      item.Path,
                      "2278.59",
                      item.Path,
                      "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat.",
                      item.Name,
                      47,
                      16,
                      group4) { Level1 = "+11.52", Level2 = "+0.50%", High = Visibility.Visible });

                    }
                    this.AllGroups.Add(group4);


                }
                catch (Exception ex)
                {
                    //  MessageBlock.Text += "Exception encountered: " + ex.Message + "\n";
                }
            } 

    I have slimier kind of method that loading share point library images. it also has some problem when i use URL -http://info.expo.com/EHL/1.jpg but i have used same unpublished one it worked perfect (http://info/EHL/1.jpg)

    any help greatly appreciated

    Kind regards

    Radika

                                                       
    Wednesday, September 25, 2013 7:59 AM

All replies

  • Your app doesn't have access to the paths in the PicturesLibrary. It needs to use the StorageFiles rather than extracting the Paths and bypassing them. I discussed this in my blog entry Skip the path: stick to the StorageFile - Windows Store Developer ...

    --Rob

    Wednesday, September 25, 2013 1:49 PM
    Moderator
  • Thanks Rob 

    But my problem is only the image is not rendering. all other file related meta data is rendering without problem. wonder any thing to do with this sampledatasource.cs file image property settings

    In sampledatasouce image property settings do i need to change some thing ?

     public abstract class SampleDataCommon : Finance.Common.BindableBase
        {
            private static Uri _baseUri = new Uri("ms-appx:///");

            //private static Uri _baseUri = new Uri("ms-appx-web:");

            public SampleDataCommon(String uniqueId, String title, String subtitle, String imagePath, String description)
            {
                this._uniqueId = uniqueId;
                this._title = title;
                this._subtitle = subtitle;
                this._description = description;
                this._imagePath = imagePath;
            }

            private string _uniqueId = string.Empty;
            public string UniqueId
            {
                get { return this._uniqueId; }
                set { this.SetProperty(ref this._uniqueId, value); }
            }

            private string _title = string.Empty;
            public string Title
            {
                get { return this._title; }
                set { this.SetProperty(ref this._title, value); }
            }

            private string _subtitle = string.Empty;
            public string Subtitle
            {
                get { return this._subtitle; }
                set { this.SetProperty(ref this._subtitle, value); }
            }

            private string _Level1 = string.Empty;
            public string Level1
            {
                get { return this._Level1; }
                set { this.SetProperty(ref this._Level1, value); }
            }

            private string _Level2 = string.Empty;
            public string Level2
            {
                get { return this._Level2; }
                set { this.SetProperty(ref this._Level2, value); }
            }
            private Visibility _Low = Visibility.Collapsed;
            public Visibility Low
            {
                get { return this._Low; }
                set { this.SetProperty(ref this._Low, value); }
            }

            private Visibility _High = Visibility.Collapsed;
            public Visibility High
            {
                get { return this._High; }
                set { this.SetProperty(ref this._High, value); }
            }

            

            private string _description = string.Empty;
            public string Description
            {
                get { return this._description; }
                set { this.SetProperty(ref this._description, value); }
            }

            private ImageSource _image = null;
            private String _imagePath = null;
            public ImageSource Image
            {
                get
                {
                    if (this._image == null && this._imagePath != null)
                    {
                   this._image = new BitmapImage(new Uri(SampleDataCommon._baseUri, this._imagePath));
                        //var bitmapImage = new BitmapImage();
                    
                        //bitmapImage.UriSource = new Uri(SampleDataCommon._baseUri, this._imagePath);
                    
                        //this._image = new BitmapImage(new Uri(SampleDataCommon._baseUri, this._imagePath));
                        //this._image = bitmapImage;
                    }
                    return this._image;
                }

                set
                {
                    this._imagePath = null;
                    this.SetProperty(ref this._image, value);
                }
            }

            public void SetImage(String path)
            {
                this._image = null;
                this._imagePath = path;
                this.OnPropertyChanged("Image");
            }

            public override string ToString()
            {
                return this.Title;
            }
        }

    Kind regards

    Radika

    Thursday, September 26, 2013 4:28 AM
  • Hi this is rectified 

    I have added imageStream for the read item and created bit map image in run time and assigned it for sample data item , Image property here i'm listing the brief code .. 

     private async void LoadImage()
            {
                try
                {
                    IReadOnlyList<Windows.Storage.StorageFile> resultsLibrary =
                        await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();
                 

                    var group4 = new SampleDataGroup("Group-4",
                                   "Pictures",
                                   "Group Subtitle: 1",
                                   resultsLibrary[0].Path,
                                   "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");
                    


                    foreach (var item in resultsLibrary)
                    {
                        //new Movie {Title = item.Title,Category = item.Category,Subtitle = "The Towani family civilian shuttlecraft crashes on the forest moon of Endor.", Image = item.Category
                        //Movies.Add(new Movie { Title = item.Title, Category = item.Category, Subtitle = item.Subtitle, Image = item.Image });
                        //};
                        Windows.Storage.Streams.IRandomAccessStream imageStream =
                            await item.OpenAsync(Windows.Storage.FileAccessMode.Read);
                        Windows.UI.Xaml.Media.Imaging.BitmapImage imageBitmap =
                            new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                        imageBitmap.SetSource(imageStream);
                       
                 
                        SampleDataItem sdata = new SampleDataItem(item.DisplayName + "Group-1",
                    item.Path,
                      "2278.59",
                      null,
                      "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat.",
                      item.Name,
                      47,
                      16,
                      group4);
                        sdata.Image = imageBitmap;
                        group4.Items.Add(sdata);
                   
                        

                    }
                    this.AllGroups.Add(group4);


                }
                catch (Exception ex)
                {
                  //  MessageBlock.Text += "Exception encountered: " + ex.Message + "\n";
                }
            }

    Regards 

    Radika


    • Edited by Radika Thursday, September 26, 2013 7:16 AM
    Thursday, September 26, 2013 7:12 AM