Hank
Hank

Reputation: 8477

Distortion when resizing/scaling WPF Image

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:

Has anyone seen this behavior before, and do you have any thoughts?

At 20% of original size:

alt text http://maylark.com/Scale20.png

At 26% of original size:

alt text http://maylark.com/Scale26.png

At 41% of original size:

alt text http://maylark.com/Scale41.png

At 64% of original size:

alt text http://maylark.com/Scale64.png

At 80% of original size:

alt text http://maylark.com/Scale80.png

Upvotes: 1

Views: 2465

Answers (3)

Hank
Hank

Reputation: 8477

So after many hours of trying to isolate the problem, I decided to just start over in a new Visual Studio solution and one by one put the components back. Everything was working in the new solution, and finally I had all the classes back and everything was still working!

It turned out to be build setting: the non-functional version was being multi-targeted for "Any CPU," but the new solution was targeting "x86".

Apparently there is a glitch in the Windows XP x64 graphics subsystem for "Any CPU" programs, because either switching to x86 or running on Vista / 7 solved the problem.

I have posted this in the hopes that it will save someone else some time.

Upvotes: 2

Andrew Bienert
Andrew Bienert

Reputation: 348

Try to eliminate the variables. OS, Hardware and drivers (as pointed out in the first answer) and also the image formats that you are using. You mentioned that not all images have the problem? Are there any differences with those image formats? eg. Bit depth, color etc. Also can you resize the images in some other tool, say IrfanView, and create the same problems. That might help point to a driver issue.

The way the images are rendering looks suspiciously like the image stride is getting screwed under the hood.

Upvotes: 0

Abe Heidebrecht
Abe Heidebrecht

Reputation: 30498

A lot of WPF rendering bugs are caused by video drivers, specifically with the nVidia Quadro cards. Have you tried updating your drivers?

Upvotes: 0

Related Questions