This project is read-only.

load thumbs into a list

Sep 15, 2010 at 11:31 AM

Hi Tom

i tryed to change you panorama demopage to load 8 thumb images instead your 8 blue square.
i'm using this code but i recieve an exception immediately.
please can you give me a solution on this problem?possible to have a new method for Texture class to load an image from file system?

best regards

            Texture texture = null;
            String imagename="";
            Dictionary<string, Texture> cachedPictures = new Dictionary<string, Texture>(8);
            List<Item> items = new List<Item>(8);

            int i = 0;
            foreach (FileInfo image in mypictureThumbFiles)
            {
                if (i>7)
                   break;
                if (!cachedPictures.TryGetValue(image.Name, out texture))
                {
                    imagename = image.Name;
                    string thumbpath = image.FullName;
                    FileStream str = new FileStream(thumbpath, FileMode.Open, FileAccess.Read);
                    texture.LoadFromStream(str, TextureFormat.RGB565);
                    str.Close();
                    

                }
                cachedPictures.Add(imagename, texture);
                i++;
            }

 

 

Sep 15, 2010 at 2:44 PM

texture is always null, that's where the exception comes from.

it should look like this:

 

           Texture texture = null;
            String imagename="";
            Dictionary<string, Texture> cachedPictures = new Dictionary<string, Texture>(8);
            List<Item> items = new List<Item>(8);

            int i = 0;
            foreach (FileInfo image in mypictureThumbFiles)
            {
                if (i>7)
                   break;
                if (!cachedPictures.TryGetValue(image.Name, out texture))
                { 
                    texture=new Texture();
                    imagename = image.Name;
                    string thumbpath = image.FullName;
                    using (FileStream str = new FileStream(thumbpath, FileMode.Open, FileAccess.Read))
                    {
                        texture.LoadFromStream(str, TextureFormat.RGB565);
                        str.Close();
                    }
                    cachedPictures.Add(imagename, texture);
                }
                i++;
            }

 

Sep 15, 2010 at 2:48 PM

WOW

what i have missed...................i'm  a donkey man.

Thak you TOM