Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am uplaoding a image into my form and place the image into picture box.but the image size too large(does not fit into my picturebox). how can i reduce my images and display into picture box.


private void btn_browspass_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "image files|*.jpg;*.png;*.gif";
            DialogResult dr = ofd.ShowDialog();
            if (dr == DialogResult.Cancel)
                return;
            pictureBox1.Image = Image.FromFile(ofd.FileName);
            txt_pass.Text = ofd.FileName;
        }

its my code. here were i can resize the uploading image size. note:(my picture box size is: 258, 268 ).
Posted

Visit http://msdn.microsoft.com/en-us/library/224wtx7a(v=vs.85).aspx[^]

It tells you properties on the picturebox control that alter how the image is displayed. This way you don't actually alter the original image.
 
Share this answer
 
Hi,


If you just want to shrink your image then you can use below code, this is quick fix. if you really need to change the size of the picture then you need to write additional code.

To shrink image :
C#
pictureBox1.SizeMode =  PictureBoxSizeMode.StretchImage

To change size of image :
Check this discussion[^]


Thanks
-Amit
 
Share this answer
 
Use that if you wants to keep the size ratio, best mode in most case.



pictureBox1.SizeMode= System.Windows.Forms.PictureBoxSizeMode.Zoom;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900