在面板上显示图像

发布于 2024-10-06 21:51:33 字数 1238 浏览 6 评论 0原文

这是我的代码片段...

 public void btn_browse_Click_Click(object sender, EventArgs e)
    {

        try
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            if (open.ShowDialog() == DialogResult.OK)
            {
                scan.Enabled = true;
                pic = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
                pic2 = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);                                   

                pic = new Bitmap(open.FileName);
                pic2 = new Bitmap(open.FileName);

                pictureBox1.Image = pic;
                pictureBox2.Image = pic2;
                pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                textBox1.Text = open.FileName;
                pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;



            } // end of if opendialog


        } // end of try

        catch (Exception)
        {
            throw new ApplicationException("Failed loading image");
        }


    }

问题是:我是否能够显示在面板而不是 PictureBox 上浏览的图像?

this i a snippet of my code....

 public void btn_browse_Click_Click(object sender, EventArgs e)
    {

        try
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            if (open.ShowDialog() == DialogResult.OK)
            {
                scan.Enabled = true;
                pic = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
                pic2 = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);                                   

                pic = new Bitmap(open.FileName);
                pic2 = new Bitmap(open.FileName);

                pictureBox1.Image = pic;
                pictureBox2.Image = pic2;
                pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                textBox1.Text = open.FileName;
                pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;



            } // end of if opendialog


        } // end of try

        catch (Exception)
        {
            throw new ApplicationException("Failed loading image");
        }


    }

The question is: Am i able to display my image browsed on a Panel instead of a PictureBox ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ゝ杯具 2024-10-13 21:51:33

您可以将面板的 BackGroundImage 设置为该图像。
<代码>
panel.BackgroundImage = Image.FromFile(open.FileName);

应该做到这一点。

You could set the BackGroundImage of the panel to the image.

panel.BackgroundImage = Image.FromFile(open.FileName);

Should do the trick.

场罚期间 2024-10-13 21:51:33

基本上,PictureBox 用于显示图像,而Panel 用于绘图 在里面(曲线,直线,矩形,......)

所以我建议最好使用pictureBox,但是如果你想在面板中显示图像。

  1. 您可以在paint事件上绘制它
  2. 使用BackgroundImage属性。

Basically PictureBox is made to display images while Panel is for drawing in it(curves, lines, rectangles,....)

So I suggest better to use pictureBox, but if you want to show image in panel.

  1. You can draw it on paint event
    OR
  2. Use BackgroundImage property.
爱的那么颓废 2024-10-13 21:51:33

是的。 Panel 类 有一个名为BackImageUrl。只需指定要用作背景的图片的 URL 即可。

Yes. The Panel class has a member called BackImageUrl. Just specify the URL of the picture you want to use as the background.

小…红帽 2024-10-13 21:51:33

对于 winforms,您可以使用 BackgroundImage 和 BackgroundImageLayout 属性。

For winforms, you can use the BackgroundImage and BackgroundImageLayout properties of the Panel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文