Load Multi Picutres in to listViewBox using an Array

Feb 16 2009 9:34 PM

hi,

i need to know how can i give open dialog box file path to here...

string[] pathes = new string[] { to here};

if i put like this

      string[] pathes = new string[] { @"c:\pic\h.jpg"};

      string[] pathes = new string[] { dlg.fineName}; this way also working but only one picturecan load....

if i put string[] pathes = new string[] { dlg.fileNames}; if i put like this got ERROR........

 

i can load picture but its static.when user wants to load many pictues in to an array using open load box, if i could give the open dialog box path to there i can load dynamicaly. isn't it????

 i mean by open dialog box path is......some thing like when we use pictureBox....

            EG: -  pictureBox1.Image = image.fromFile(dlg.filname);

is there got way to give path like this.....to array......???

 

public partial class Form10 : Form

    {

        public Form10()

        {

            InitializeComponent();

        }

 

        private void Form10_Load(object sender, EventArgs e)

        {

            ImageList imageList = new ImageList();

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

            imageList.ColorDepth = ColorDepth.Depth32Bit;

 

            string[] pathes = new string[] { "*****i need to give OPEN DIALOGBOX PATH TO HERE"*******};

 

            foreach (string path in pathes)

            {

                Image img1 = Image.FromFile(path);

                imageList.Images.Add(getThumbnaiImage(imageList.ImageSize.Width, img1));

            }

 

            for (int j = 0; j < pathes.Length; j++)

            {

                this.listView1.Items.Add("Image\n aaaaaa\r\n bbbbbbbbbbbbbbbbbbbbb ");

                this.listView1.Items[j].ImageIndex = j;

            }

 

            this.listView1.View = View.LargeIcon;

            this.listView1.LargeImageList = imageList;

        }

 

        private Image getThumbnaiImage(int width, Image img)

        {

            Image thumb = new Bitmap(width, width);

            Image tmp = null;


            //If the original image is small than the Thumbnail size, just draw in the center

            if (img.Width < width && img.Height < width)

            {

                using (Graphics g = Graphics.FromImage(thumb))

                {

                    int xoffset = (int)((width - img.Width) / 2);

                    int yoffset = (int)((width - img.Height) / 2);

                    g.DrawImage(img, xoffset, yoffset, img.Width, img.Height);

                }

            }

            else //Otherwise we have to get the thumbnail for drawing

            {

                Image.GetThumbnailImageAbort myCallback = new

                    Image.GetThumbnailImageAbort(ThumbnailCallback);

 

                if (img.Width == img.Height)

                {

                    thumb = img.GetThumbnailImage(

                             width, width,

                             myCallback, IntPtr.Zero);

                }

                else

                {

                    int k = 0;

                    int xoffset = 0;

                    int yoffset = 0;

 

                    if (img.Width < img.Height)

                    {

                        k = (int)(width * img.Width / img.Height);

                        tmp = img.GetThumbnailImage(k, width, myCallback, IntPtr.Zero);

                        xoffset = (int)((width - k) / 2);

 

                    }

 

                    if (img.Width > img.Height)

                    {

                        k = (int)(width * img.Height / img.Width);

                        tmp = img.GetThumbnailImage(width, k, myCallback, IntPtr.Zero);

                        yoffset = (int)((width - k) / 2);

                    }

 

                    using (Graphics g = Graphics.FromImage(thumb))

                    {

                        g.DrawImage(tmp, xoffset, yoffset, tmp.Width, tmp.Height);

                    }

                }

            }

 

            using (Graphics g = Graphics.FromImage(thumb))

            {

                g.DrawRectangle(Pens.Green, 0, 0, thumb.Width - 1, thumb.Height - 1);

            }

 

            return thumb;

        }

 

        public bool ThumbnailCallback()

        {

            return true;

        }

    }

 

pl if anyone can help me.....thx a lot u all.....

 

 

 


Answers (9)