上传图像并将其放在图片框中,并将图像大小调整为图片框大小 [英] upload image and place it in picture box and resize image size into picture box size

查看:107
本文介绍了上传图像并将其放在图片框中,并将图像大小调整为图片框大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图像上传到我的表单中并将图像放入图片框中。但图像尺寸太大(不适合我的图片框)。如何减少我的图像并显示到图片框中。





 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;
}



我的代码。这是我可以调整上传图像大小。注意:(我的图片框尺寸为:258,268)。

解决方案

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



它告诉您图片框控件上的属性会改变图像的显示方式。这样你就不会改变原来的形象了。


你好,





如果您只想缩小图像,那么您可以使用下面的代码,这是快速修复。如果你真的需要改变图片的大小,那么你需要编写额外的代码。



缩小图片:

<预郎= C#> pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage



要改变图像尺寸:

查看此讨论 [ ^ ]





谢谢

-Amit


见以下链接



http:/ /msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspx [ ^ ]

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 ).

解决方案

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.


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 :

pictureBox1.SizeMode =  PictureBoxSizeMode.StretchImage


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


Thanks
-Amit


See below link

http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspx[^]


这篇关于上传图像并将其放在图片框中,并将图像大小调整为图片框大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆