Saturday, January 8, 2011

Display multiple thumbnail image in Listview

ImageList imageList = new ImageList();

            OpenFileDialog opend1 = new OpenFileDialog();

             opend1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";

            opend1.Multiselect = true;



             if (opend1.ShowDialog() == DialogResult.OK)

             {

                 listView1.View = View.LargeIcon;

                 imageList.ImageSize = new Size(100, 100);

                 for (int c = 0; c < opend1.FileNames.Length; c++)

                {

                   Image i = Image.FromFile(opend1.FileNames[c].ToString());

                   Image img = i.GetThumbnailImage(100, 100, null, new IntPtr());

                     imageList.Images.Add(img);

                }



                listView1.LargeImageList = imageList;



                 for (int j = 0; j < imageList.Images.Count; j++)

                {

                   ListViewItem lstItem = new ListViewItem();

                     lstItem.ImageIndex = j;

                     listView1.Items.Add(lstItem);

                }

            }

No comments:

Post a Comment