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

4
我使用以下代码创建了一张图片。
        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)。现在,如何将更改(缩放或任何更改)应用于原始图像?
谢谢大家;
1个回答

0

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

看一下类似AForge.Net这样的东西,它具有各种操作图像的方法,允许控制转换的质量等。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接