如何在 C# 中以编程方式放大和缩小图像?
我希望能够缩放(-/+)放置在面板下的图像。我希望在该面板中显示图像的缩放版本。我怎样才能在 C# 中实现这一目标?
简而言之,当我在 C# 中以编程方式单击图像时,如何放大和缩小图像?
I would like to be able to zoom (-/+) an image that is placed under a panel. I would like the zoomed version of the image to be displayed within that panel. How can I achieve this in C#?
In simple words, how can I zoom an image in and out when I click on the image programmatically in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用GDI+,那么您当然可以通过使用Matrix变换类来做到这一点,如下所示......
当您想要放大或缩小时,您只需改变使用的缩放值。
If you use GDI+ then you can certainly do this by using the Matrix transform class in something like the following manner...
When you want to zoom in or out you are just altering the scaling values used.
您需要使用 GDI+ 绘图函数(在 .NET Framework 中作为
Graphics
类)来执行此操作。本质上,您将在显示面板中重新绘制基础图像的缩放版本。使用类似
Graphics.DrawImage
,您所要做的就是指定基本图像、源矩形(基本图像中要放大的部分)和目标矩形(新的缩放图像的尺寸)。这里有一个教程,您可能会发现值得您花时间查看(源代码下载链接位于页面底部):http://www.vcskicks.com/image-zoom.php
如果这只是激起了您对 C# 图形的兴趣,请查看 本文更全面地介绍其图形相关功能。
You'll need to use the GDI+ drawing functions (exposed in the .NET Framework as methods of the
Graphics
class) to do this. Essentially, you'll be redrawing a zoomed version of the base image into the display panel.Using something like
Graphics.DrawImage
, all you have to do is specify the base image, the source rectangle (the portion of the base image to zoom in on), and the destination rectangle (the dimensions of the new, zoomed image).There's a tutorial available here that you may find worth your time to check out (source code download link is at the bottom of the page): http://www.vcskicks.com/image-zoom.php
If this has only just whet your appetite for graphics in C#, check out this article for a more comprehensive introduction to its graphics-related capabilities.
免责声明:我在 Atalasoft 工作
我们的 DotImage Photo SDK 是免费的,并且有一个 WinForms 控件,该控件具有此功能和许多其他功能(平移、自动缩放、放大镜等)
Disclaimer: I work for Atalasoft
Our DotImage Photo SDK is free and has a WinForms control that has this and many other features (panning, autozoom, magnifying glass, etc)