Apply Zoom in / out to Origin Image in WPF

I created an image with this code

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; } } 

I can enlarge / reduce the image on this image

  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); } 

but when I get ActualWidth or Width or ActualHeight / Height, the number 100 is returned. This means that these changes do not apply to the original image (myImage). Now How to apply changes (increase or any changes) to the original image?

Tanx all;

+4
source share
1 answer

Transforms only affect the appearance / layout of the object to which they are applied, and will not make any changes directly to the source code. To do this, you need to resize the image yourself, reading the scaling values ​​and applying them to the original width and height.

Look at something like AForge.Net , which has a lot of methods for image processing, allowing you to control the quality of the conversion, etc.

0
source

All Articles