private void button1_Click(object sender, EventArgs e) { int j; openFileDialog1.Multiselect = true; if ( openFileDialog1.ShowDialog() == DialogResult.OK) { string[] file = openFileDialog1.FileNames; // To put the first image selected in pictureBox1 Image img = Image.FromFile(file[0]); Image img1 = ResizeImage(img,pictureBox1.Width,pictureBox1.Height); pictureBox1.Image = img1; //to put the rest of images selected, in pictureboxes present in flowlayoutpanel // textbox1 to limit the number of images according to user. for( j=0 ;j< Convert.ToInt32(textBox1.Text) ;j++) { try { PictureBox pb = new PictureBox(); Image loadedimage1 = Image.FromFile(file[j]); pb.Size = new System.Drawing.Size(100, 100); Image img3 = ResizeImage(loadedimage1, pb.Width, pb.Height); pb.Image = img3; flowLayoutPanel1.Controls.Add(pb); pb.MouseClick += new MouseEventHandler(picturebox_load); } catch (Exception ex) { MessageBox.Show(". You may not have permission to read the file, or " + "it may be corrupt.\n\nReported error: " + ex.Message); } } } } // load image on mouseclick in picturebox1 public void picturebox_load(object sender, MouseEventArgs e) { PictureBox pb = (PictureBox)sender; Image img2 = pb.Image; Image img3 = ResizeImage(img2, pictureBox1.Width, pictureBox1.Height); pictureBox1.Image = img3; } public static System.Drawing.Bitmap ResizeImage(System.Drawing.Image image, int width, int height) { //a holder for the result Bitmap result = new Bitmap(width, height); //use a graphics object to draw the resized image into the bitmap using (Graphics graphics = Graphics.FromImage(result)) { //set the resize quality modes to high quality graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //draw the image into the target bitmap graphics.DrawImage(image, 0, 0, result.Width, result.Height); } //return the resulting bitmap return result; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)