gpt4 book ai didi

c# - 在 WPF 中对原始图像应用放大/缩小

转载 作者:行者123 更新时间:2023-11-30 13:05:05 25 4
gpt4 key购买 nike

我用这段代码创建了一个图像

        OpenFileDialog dlg = new OpenFileDialog();
dlg.FileName = ""; // Default file name
myImage = new Image();
try
{
Nullable<bool> result = dlg.ShowDialog();

if (result == true)
{
string sUri = @dlg.FileName;
Uri src = new Uri(sUri, UriKind.RelativeOrAbsolute);
BitmapImage bmp = new BitmapImage(src);
myImage.Source = bmp;
myImage.Width = 100;
myImage.Height = 100;
}
}

我可以放大/缩小这张图片

    public void Scale(int i, Point center)
{
Matrix m = myImage.RenderTransform.Value;
if (i > 0)
m.ScaleAtPrepend(1.1, 1.1, center.X, center.Y);
else
m.ScaleAtPrepend(1 / 1.1, 1 / 1.1, center.X, center.Y);

myImage.RenderTransform = new MatrixTransform(m);
}

但是当我得到 ActualWidth 或 Width 或 ActualHeight/Height 时返回数字 100。这意味着这些更改不适用于原始图像 (myImage)。现在如何将更改(缩放或任何更改)应用到原始图像?

全部转账;

最佳答案

变换只会影响应用它们的对象的外观/布局,不会直接对源进行任何更改。为此,您需要自己调整图像大小,读取缩放值并将其应用于原始宽度和高度。

看看像 AForge.Net 这样的东西它有无数种处理图像的方法,允许控制转换的质量等。

关于c# - 在 WPF 中对原始图像应用放大/缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6243466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com