如何放大和缩小图片框? [英] How do I zoom in and out of a picturebox?

查看:103
本文介绍了如何放大和缩小图片框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个条目:我正在尝试放大和缩小图像。我将在下面粘贴我的代码。截至目前,它似乎是放大和缩小pictureBox本身而不是加载到pictureBox中的图像(如果这是有意义的)当我编译并运行应用程序时,在尝试缩放时,图像将保持不变相同的大小,你可以看到pictureBox网格放大和缩小。我在这做错了什么?



First entry: I am trying to zoom in and out of an image. I will paste my code below. As of now, it seems to be zooming in and out of the pictureBox itself and not the image that is loaded into the pictureBox (if that makes sense) When I compile and run the application, while trying to zoom, the image will stay the same size while you can see the pictureBox grid zooming in and out. What am I doing wrong here?

private void panel1_Paint(object sender, PaintEventArgs e) 
        {
            panel1.AutoScroll = true;
            pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
        }

        void pictureBox1_MouseHover(object sender, EventArgs e)
        {
            pictureBox1.Focus();
        }

        void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta <= 0) // zoom in
            {
                Convert.ToInt32(pictureBox1.Image.Width * pictureBox1.Image.Height);
                Convert.ToInt32(pictureBox1.Image.Height * pictureBox1.Image.Height);
            }
            
            else if (e.Delta >= 0) //zoom out
            {
                Convert.ToInt32(pictureBox1.Image.Width / pictureBox1.Image.Height);
                Convert.ToInt32(pictureBox1.Image.Height / pictureBox1.Image.Height);
            }
            
            pictureBox1.Width += Convert.ToInt32(pictureBox1.Image.Width * e.Delta / 1000);
            pictureBox1.Height += Convert.ToInt32(pictureBox1.Image.Height * e.Delta / 1000);
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
            pictureBox1.MouseHover += new EventHandler(pictureBox1_MouseHover);
        }

推荐答案

这不是不可能的,用<$ c做这样的事情是没有意义的$ C>图片框。这种冗余控制只能帮助您尝试做一些非常简单的事情,比如显示静态图片。在所有其他情况下,你应该自己渲染内容。



请查看我过去的答案:

在图片框中添加图片 [ ^ ],

用C#绘制一个矩形 [ ^ ],

如何从旧图纸中清除面板 [ ^ ]。



有关渲染o的信息f图形,请看我过去的答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



这个答案特别是关于缩放问题:用C#.net鼠标缩放图像轮 [ ^ ]。



祝你好运,

-SA
Not that is it impossible, it's just does not make sense to do anything like that with PictureBox. This redundant control can only help is your try to do something very simple, like showing a static picture. In all other cases, you should render the content yourself.

Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

For information on rendering of graphics, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

And this answers was specifically on the zoom problem: Zoom image in C# .net mouse wheel[^].

Good luck,
—SA


这个问题已在互联网上多次询问。



请参阅以下链接获取示例和/或搜索谷歌了解更多信息:



http://social.msdn.microsoft.com/Forums/en-US/50d2ad98-405e-4943-a300-021fd3ecbaa4/how-to-zoom-in-and-out-in-picture-box?forum= vblanguage [ ^ ]



http://stackoverflow.com/questions/11734934/how-to-zoom-in-and-zoom-out-a-image-in-picturebox-using-mouse-wheels-in-c [<一个href =http://stackoverflow.com/questions/11734934/how-to-zoom-in-and-zoom-out-a-image-in-picturebox-using-mouse-wheels-in-ctarget = _blanktitle =新窗口> ^ ]
This question has been asked many times on the internet.

See the following links for examples and/or search google for more:

http://social.msdn.microsoft.com/Forums/en-US/50d2ad98-405e-4943-a300-021fd3ecbaa4/how-to-zoom-in-and-out-in-picture-box?forum=vblanguage[^]

http://stackoverflow.com/questions/11734934/how-to-zoom-in-and-zoom-out-a-image-in-picturebox-using-mouse-wheels-in-c[^]


这篇关于如何放大和缩小图片框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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