I have a program that displays an image, and the user can resize the image in the window (e.g. by rolling the mouse wheel). I scale the image using a RenderTransform, like this:
<Image x:Name="CurrentImage">
<Image.RenderTransform>
<TransformGroup>
<TranslateTransform x:Name="Translate" X="0" Y="0"/>
<ScaleTransform x:Name="Scale" ScaleX="1" ScaleY="1"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
Then I just change the ScaleX
and ScaleY
properties. The image resizes as expected.
However, at certain scales, the image gets very distorted. Below about 20% and above about 80% it displays fine, but for resolutions in between, some or all of the image is distorted. See screenshots below.
A couple other details:
- the 2 Windows XP machines I tried this on had the same corruption, but a Windows 7 laptop did NOT exhibit the problem.
- I also tried replacing the
RenderTransform
with just scaling the Image by itself using theHeight
andWidth
properties, but it made no difference. - Not all images have a problem, and the ones that do will sometimes do it at different scale factors. Larger images seem to be worse, but I have not systematically measured.
- .NET 3.5 and .NET 4 RC both exhibit the behavior.
Has anyone seen this behavior before, and do you have any thoughts?
At 20% of original size:
At 26% of original size:
At 41% of original size:
At 64% of original size:
At 80% of original size: