4
votes

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 zoom in/out 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 the ActualWidth or Width or ActualHeight/Height returns the number 100. this means that these changes not applied to origin image (myImage). Now How to apply the changes (zoom or any changes) to origin Image?

Tanx all;

1

1 Answers

0
votes

Transforms only affect the appearance / layout of the object they are applied to and won't make any changes directly to the source. For this you'll need to resize the image yourself, reading the values of the scaling and applying those to the original width and height.

Take a look at something like AForge.Net which has myriad methods for manipulating images allowing control over the quality of the transformation etc.