2011-06-05 31 views
4

我创建的图像与此代码应用放大/缩小到原产地形象WPF

 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)。 现在如何将更改(缩放或任何更改)应用于原始图像?

Tanx all;

回答

0

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

看看像AForge.Net这样的操作图像有很多方法可以控制转换的质量等。