views:

333

answers:

3

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 the Height and Width 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:

alt text

At 26% of original size:

alt text

At 41% of original size:

alt text

At 64% of original size:

alt text

At 80% of original size:

alt text

A: 

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

Abe Heidebrecht
The main system I work on does have a Quadro card, but I also reproduced the problem on a Matrox card machine. All have the latest drivers available. So far the only common theme I can find is Windows XP and/or DirectX 9c.
Henry Jackson
A: 

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.

Andrew Bienert
Thank you for the help. It turned out to be a build setting, which apparently exposed a bug in some graphics subsystem (see my own answer to the question).
Henry Jackson
A: 

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.

Henry Jackson