locked
How To Get Resources RRS feed

  • Question

  • Hi,

    i am using like this.

       private Dictionary<int, Image> GetImages()
            {
                List<Stream> picsStrm = new List<Stream>();

                Assembly asmb = Assembly.GetEntryAssembly();
                string[] picNames = asmb.GetManifestResourceNames();

                foreach (string s in picNames)
                {
                    if (s.EndsWith(".png"))
                    {
                        Stream strm = asmb.GetManifestResourceStream(s);
                        if (strm != null)
                        {
                            picsStrm.Add(strm);
                        }
                    }
                }

                Dictionary<int, Image> images = new Dictionary<int, Image>();

                int i = 0;

                foreach (Stream strm in picsStrm)
                {

                    PngBitmapDecoder decoder = new PngBitmapDecoder(strm,
                        BitmapCreateOptions.PreservePixelFormat,
                        BitmapCacheOption.Default);
                    BitmapSource bitmap = decoder.Frames[0] as BitmapSource;
                    Image img = new Image();
                    img.Source = bitmap;
                    img.Stretch = Stretch.UniformToFill;

                    images.Add(i, img);
                    i++;

                    strm.Close();
                }
                return images;
            }
        

    and my project contain a folder of .png images  but i am not getting all images using this 

    please if any buddy know than let me know that how to solve it.

    Regard

    balram

     

    Tuesday, December 4, 2012 11:52 AM

Answers

  • If you are getting some of the files and not others then it is one of three problems

    1) the png file doesn't contain a valid picture.  Try opening up the file with another viewer.  The file may be in a newer version of png that isn't supported in th ecurrent viewer.

    2) The file may not end in the extension '.png'.  Make sure the isn't a trailing white characrer in the file name.

    3) You don't have permission to open the file.  Try opening the file manually with another viewer.


    jdweng

    • Marked as answer by Balram Sharma Wednesday, December 5, 2012 6:27 AM
    Tuesday, December 4, 2012 1:12 PM

All replies

  • If you are getting some of the files and not others then it is one of three problems

    1) the png file doesn't contain a valid picture.  Try opening up the file with another viewer.  The file may be in a newer version of png that isn't supported in th ecurrent viewer.

    2) The file may not end in the extension '.png'.  Make sure the isn't a trailing white characrer in the file name.

    3) You don't have permission to open the file.  Try opening the file manually with another viewer.


    jdweng

    • Marked as answer by Balram Sharma Wednesday, December 5, 2012 6:27 AM
    Tuesday, December 4, 2012 1:12 PM
  • I thought if you couldn't open the file you  woldn't be abble to display the file.  There are two posible resons why you aren't seeing all the pcitures

    1) The pictures are there put are laid ontop of each other.

    2) You may not be getting all the files because they are in subfolders.

    It would be helpful if you can determine which pictures are showing and which pictures aren't showing.


    jdweng

    Wednesday, December 5, 2012 6:26 AM
  • Thanks Joel.

    Your 3rd point is right, I have changed in properties .

    Regards 

    balram

    Wednesday, December 5, 2012 6:29 AM