如何使用wpf放大图像控制中的缩小 [英] How to zoom in zoom out in image control using wpf

查看:135
本文介绍了如何使用wpf放大图像控制中的缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用wpf

推荐答案

在图像控件中放大和缩小?对WPF中的缩放有不同的理解,所以答案取决于确切的行为你想实现。例如,如果您将某些内容放在类 ViewBox 的实例中,则会在调整大小时显示此内容 ViewBox https://msdn.microsoft。 com / en-us / library / system.windows.controls.viewbox%28v = vs.110%29.aspx [ ^ ]。



另见我过去的答案:有效缩放屏幕不同分辨率的人工制品...... [ ^ ],

比例siz e image wpf window [ ^ ]。



另一种方法是缩放位图,您可以将其用作图像的来源(https://msdn.microsoft.com/en-us/library/system .windows.controls.image.source(v = vs.110).aspx [ ^ ])。这可以通过使用名为 TransformedBitmap 的位图源类型来完成:

There are different understanding of "zoom" in WPF, so the answer depends on the exact behavior you want to achieve. For example, if you put some content in an instance of the class ViewBox, this content will be shown as you resize ViewBox: https://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox%28v=vs.110%29.aspx[^].

See also my past answer: Effective scaling of screen artefacts at differing resolutions...[^],
proportional size image wpf window[^].

Another approach is zooming a bitmap which you can use as the source of your image (https://msdn.microsoft.com/en-us/library/system.windows.controls.image.source(v=vs.110).aspx[^]). This can be done by using the type of bitmap source called TransformedBitmap:
BitmapSource imageSource = // let's say, you take it from file...
// ...and use as a Source in some image

// eventually, you want to scale it:

double factor = //...

// ...

imageSource = new TransformedBitmap(imageSource, new ScaleTransform(factor, factor));
// see other constructors of ScaleTransform, say, to define custom center point





请参阅:

https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.transformedbitmap%28v = vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.media.transform%28v=vs.110 %29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform(V = vs.110) .aspx [ ^ ]。



-SA



Please see:
https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.transformedbitmap%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.media.transform%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform(v=vs.110).aspx[^].

—SA


这篇关于如何使用wpf放大图像控制中的缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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