Jump to content

Why i need wait long time to download images?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
mario

mario

    Newbie

  • Members
  • Pip
  • 5 posts
HI all,
i'm trying to populate a panel with an array of picture but when i debug the program is so slow to download the picture in the panel.
i have this code snippet :


 public partial class ArtLabel : Form

    {

        private System.Windows.Forms.PictureBox[] imgArray;	//Declaring array of PictureBox

        public static string ImageToShow;

        private int NumOfFiles;

        private string[] imgExtension;

    

        

        public ArtLabel()

        {

            InitializeComponent();

            panel1.VerticalScroll.Visible = true;

            panel1.VerticalScroll.Enabled = true;

          //  panel1.VerticalScroll.Maximum = 1000;

            panel1.VerticalScroll.Value = panel1.VerticalScroll.Maximum;

 

        }


        private void ArtLabel_Load(object sender, EventArgs e)

        {

           GetPicture4(@"D:\\Music\\");

        }


        private bool ThumbnailCallback()

        {

            return false;

        }


        private void ARR(int cNumber, string exc)

        {

         int Xpos = 8;

            int Ypos = 8;

            Image img;

            Image.GetThumbnailImageAbort myCallback =

            new Image.GetThumbnailImageAbort(ThumbnailCallback);

            imgArray = new System.Windows.Forms.PictureBox[cNumber]; // assign number array 

            for (int i = 0; i < cNumber; i++)

            {

                imgArray[i] = new System.Windows.Forms.PictureBox(); // Initialize one variable

               if (Xpos > 432) // six images in a line

                {

                    Xpos = 8; // leave eight pixels at Left 

                    Ypos = Ypos + 72;  // height of image + 8

                }


                        imgArray[i].Left = Xpos;

                        imgArray[i].Top = Ypos;

                        imgArray[i].Width = 64;

                        imgArray[i].Height = 64;

                        imgArray[i].Visible = true;

                        imgArray[i].SizeMode = PictureBoxSizeMode.StretchImage;

                        img = Image.FromFile(exc);

                        imgArray[i].Tag = exc;

                        imgArray[i].Click += new System.EventHandler(ClickImage);

                        imgArray[i].Image = img.GetThumbnailImage(64, 64, myCallback, IntPtr.Zero);

                        panel1.Controls.Add(imgArray[i]);

                        Application.DoEvents();

                        Xpos = Xpos + 72;  


            }


        }


        private List<string> GetPicture4(string Folder)

        {

            DirectoryInfo dir = new DirectoryInfo(Folder);

            List<string> str = new List<string>();

            FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);

            int NumOfFiles = files.Length; 

            imgExtension = new string[NumOfFiles];


            for (int i = 0; i < NumOfFiles; i++)

            {

                ARR(i, files[i].FullName); 

                str.Add(files[i].FullName);

            }


            return str;



        }


        // The Event to click the image

        private void ClickImage(Object sender, System.EventArgs e)

        {

            ImageToShow = ((System.Windows.Forms.PictureBox)sender).Tag.ToString();

            Direcoty_Prova.ViewPicture f = new Direcoty_Prova.ViewPicture();

            f.ShowDialog();

        }


       

    }

My purpose of this code is to show the small label of Music Cd and after when i click on the small picture appear a new PictureBox with the picture in Real Size ,i can do it but the trouble if i wish store more than 30 picture in the Array of picture i must wait so long before that the form appear ,i don't know why.

Do you have any advice where i wrong in my code?

Thanks.

Nice Regards

#2
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
My god, please post the complete solution. :mellow:
http://forum.codecal...te-sources.html

#3
mario

mario

    Newbie

  • Members
  • Pip
  • 5 posts
HI ArekBulski
sorry for my distraction i attached the my project.
Have a nice day.

Attached Files



#4
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
No worry. But I have a sad news for you. The performace issue you are asking about is nothing compared to that the code doesnt work. :huh:

For a start, ARR() method is called for every picture but it also creates a new array of pictureboxes everytime. This should take place only once.

Even after I changed that, it still shows only 1 picture. I believe that something is wrong with positioning but I cant tell. When I run it in debug mode it throws some miserable exception while running without debug runs ok. But it still shows only 1 picture to me.

The performance solution is very simple: make indexing only the top folder. Use SearchOption.TopDirectoryOnly. You could show only pics from the browsed folder along with icons for subfolders. When user clicks a subfolder icon then you browse next folder. ;)

I could try to make the whole solution from scratch for you, but I guess that is not what you wanted, so I just mention it. Tell us what more we can do for you! ;)

Regards, :cool:
Arek Bulski.

Attached Files



#5
mario

mario

    Newbie

  • Members
  • Pip
  • 5 posts
Hi Arek,
Thanks for your support infact your advice make me try a solution to make it faster and stable

Quote

The performance solution is very simple: make indexing only the top folder. Use SearchOption.TopDirectoryOnly. You could show only pics from the browsed folder along with icons for subfolders. When user clicks a subfolder icon then you browse next folder.

That was the right way i followed

Glad to know people like you.

Have a happy code.

Nice Regards

#6
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
Ermmm, so your code is showing the pictures for you? It doesnt do that for me. :blink: