Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. ScaleTransform sometimes produces glaring artifacts [modified]

ScaleTransform sometimes produces glaring artifacts [modified]

Scheduled Pinned Locked Moved WPF
csharpwpftestingbeta-testinghelp
21 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fjparisIII
    wrote on last edited by
    #1

    I believe this is a bug in WPF 3.5. I've done extensive testing with the ScaleTransform class and only certain ranges produce the artifacts, but the transitions are sudden: it works at one scaling, then add 4 pixels to the size of the image and the artifacts appear. That's a high level description. Now for the nitty gritty details. If you're scaling images over a certain size, glaring artifacts will appear in the scaled images if the scaled images are larger than will fit in a box 2900x2900, or any size larger than the originals if the originals will not fit into a box 2900x2900. The larger the scaled images the worse the artifacts will be. How close the scaled images can be to the size of the original is non-linear. To avoid artifacts, the larger the original, the smaller the scaled images must be relative to the original images. The following data points were tested: 1. If you want to scale originals that fit in a 6000x6000 box, the scaled images can be no larger than 2900x2900, or artifacts in the scaled images will appear. 2. If you want to scale originals that fit in a 4288x4288 box, the scaled images can be no larger than 2904x2904, or artifacts in the scaled images will appear. 3. If you want to scale originals that fit in a 3008x3008 box, the scaled images can be no larger than 2900x2900, or artifacts in the scaled images will appear. 4. If you want to scale originals that fit into 2900x2900, you can't scale images into 2904x2904 without producing minor artifacts, but 2896x2896 produces no artifacts. 5. If you want to scale originals that fit into 1920x1920, you can scale images into a box as large as 4384x4384 without producing artifacts. 4388x4388 and larger produces artifacts. 6. If you want to scale originals that fit into 960x960, you can scale images into a box as large as 8772x8772 without producing artifacts. 8776x8776 and larger produces artifacts. I don't know whether this bug has been fixed in .NET 4.0 but hope to get around to testing this in the near future. If anyone knows a workaround, please let me know.

    modified on Saturday, December 5, 2009 8:06 PM

    I 1 Reply Last reply
    0
    • F fjparisIII

      I believe this is a bug in WPF 3.5. I've done extensive testing with the ScaleTransform class and only certain ranges produce the artifacts, but the transitions are sudden: it works at one scaling, then add 4 pixels to the size of the image and the artifacts appear. That's a high level description. Now for the nitty gritty details. If you're scaling images over a certain size, glaring artifacts will appear in the scaled images if the scaled images are larger than will fit in a box 2900x2900, or any size larger than the originals if the originals will not fit into a box 2900x2900. The larger the scaled images the worse the artifacts will be. How close the scaled images can be to the size of the original is non-linear. To avoid artifacts, the larger the original, the smaller the scaled images must be relative to the original images. The following data points were tested: 1. If you want to scale originals that fit in a 6000x6000 box, the scaled images can be no larger than 2900x2900, or artifacts in the scaled images will appear. 2. If you want to scale originals that fit in a 4288x4288 box, the scaled images can be no larger than 2904x2904, or artifacts in the scaled images will appear. 3. If you want to scale originals that fit in a 3008x3008 box, the scaled images can be no larger than 2900x2900, or artifacts in the scaled images will appear. 4. If you want to scale originals that fit into 2900x2900, you can't scale images into 2904x2904 without producing minor artifacts, but 2896x2896 produces no artifacts. 5. If you want to scale originals that fit into 1920x1920, you can scale images into a box as large as 4384x4384 without producing artifacts. 4388x4388 and larger produces artifacts. 6. If you want to scale originals that fit into 960x960, you can scale images into a box as large as 8772x8772 without producing artifacts. 8776x8776 and larger produces artifacts. I don't know whether this bug has been fixed in .NET 4.0 but hope to get around to testing this in the near future. If anyone knows a workaround, please let me know.

      modified on Saturday, December 5, 2009 8:06 PM

      I Offline
      I Offline
      Insincere Dave
      wrote on last edited by
      #2

      I don't completely understand the situation, are you enlarging or shrinking the images? You may want to post a picture too. As for the artifacts I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts. I think they changed the default in .NET 4.0 to improve performance. Are the images photos or graphics, are you animating them? If they contain 1px wide lines or grids you may need to look at the positioning of the element, this is improved in .NET 4 by using LayoutRounding there are workarounds for previous versions.

      modified on Sunday, December 6, 2009 8:05 PM

      F 2 Replies Last reply
      0
      • I Insincere Dave

        I don't completely understand the situation, are you enlarging or shrinking the images? You may want to post a picture too. As for the artifacts I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts. I think they changed the default in .NET 4.0 to improve performance. Are the images photos or graphics, are you animating them? If they contain 1px wide lines or grids you may need to look at the positioning of the element, this is improved in .NET 4 by using LayoutRounding there are workarounds for previous versions.

        modified on Sunday, December 6, 2009 8:05 PM

        F Offline
        F Offline
        fjparisIII
        wrote on last edited by
        #3

        Insincere Dave wrote:

        I don't complete understand the situation

        Do you mean the situation in my application? The user invokes my image scaling operation, supplying me with a bitmap of a photograph. He specifies a pixel rectangle into which to scale the supplied image. He's supplying an image from his camera so the image could be anything up to 6000 pixels on a side. But my scaling function is intended to scale the image down for 1:1 viewing on conventional monitors, so something smaller than 2600 pixels on a side. ScaleTransform has no problem with scaling down to that size. But one of my beta customers wanted to scale from 4288 to 3008, and all hell broke loose.

        Insincere Dave wrote:

        are you enlarging or shrinking the images?

        Well, as you could see from my attached data, I was doing both. I can push things where artifacts appear for both enlarging or shrinking the images. However, the boundaries where the artifacts appear are outside of the documented purpose of my application. Therefore in my own testing I never ran into the problem. Only when one of my beta testers "pushed the envelope" as described above did the problem arise. I then set about to characterize the problem, which the six tests I document tries to do. In previous years, I wrote a version of my current application in MFC/GDI+ that does not have this problem, and of course Photoshop doesn't have the problem. It' only when I try to scale an image into a box larger than 2900Hx2900W when the input image is larger than that box that artifacts occur. The scaled images are completely clean as long as they fit within that box. If the image exceeds that box by even 4 pixels in either width or height, the artifacts suddenly appear, and they're glaring. If the default for .NET 4.0 was changed to improve performance, this sounds like the default for 3.5 was HighQuality and the default for 4.0 is LowQuality, which to me would be a step backwards. I'm using 3.5. I couldn't actually see from the MSDN documentation what the default is.

        Insincere Dave wrote:

        You may want to post a picture too.

        You mean the scaled output? I didn't know you could post pictures on this site. Can you? If so, how? Or do you mean post a Web link outside of this forum to a scaled image with the artifacts I'm generating? The scaled images with artifacts have large blotches of solid color, some

        1 Reply Last reply
        0
        • I Insincere Dave

          I don't completely understand the situation, are you enlarging or shrinking the images? You may want to post a picture too. As for the artifacts I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts. I think they changed the default in .NET 4.0 to improve performance. Are the images photos or graphics, are you animating them? If they contain 1px wide lines or grids you may need to look at the positioning of the element, this is improved in .NET 4 by using LayoutRounding there are workarounds for previous versions.

          modified on Sunday, December 6, 2009 8:05 PM

          F Offline
          F Offline
          fjparisIII
          wrote on last edited by
          #4

          Insincere Dave wrote:

          I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts.

          I tried this suggestion. Here is my first attempt with maxDestinationHeight set to 3008 and maxDestinationWidth set to 3008:

          TransformedBitmap scaledBitmap = new TransformedBitmap();
          if (maxDestinationHeight > 2900 || maxDestinationWidth > 2900)
          {
          RenderOptions.SetBitmapScalingMode(scaledBitmap, BitmapScalingMode.HighQuality);
          }
          scaledBitmap.BeginInit();
          scaledBitmap.Source = bitmapSource;
          scaledBitmap.Transform = new ScaleTransform(scaleFactor, scaleFactor);
          scaledBitmap.EndInit();

          I actually tried all the values that IntelliSense suggested. Besides HighQuality, I also tried Fant (whatever that means), Linear, LowQuality, NearestNeighbor, and the last, Unspecified. All values produce exactly the same artifacts as as my code without an explicit SetBitmapScalingMode. I looked through the other attached properties in RenderOptions and only EdgeMode.Aliased suggested itself, but it also produced exactly the same aliases. Then I tried the following code with all the BitmapScalingMode values, and every one of them produced exactly the same glaring artifacts.

          TransformedBitmap scaledBitmap = new TransformedBitmap();
          scaledBitmap.BeginInit();
          scaledBitmap.Source = bitmapSource;
          scaledBitmap.Transform = new ScaleTransform(scaleFactor, scaleFactor);
          if (maxDestinationHeight > 2900 || maxDestinationWidth > 2900)
          {
          RenderOptions.SetBitmapScalingMode(scaledBitmap.Transform, BitmapScalingMode.HighQuality);
          }
          scaledBitmap.EndInit();

          Hopefully I'm doing something wrong that you can easily spot.

          I 1 Reply Last reply
          0
          • F fjparisIII

            Insincere Dave wrote:

            I would try changing the attached property RenderOptions.BitmapScalingMode and see if one of the modes eliminates the artifacts.

            I tried this suggestion. Here is my first attempt with maxDestinationHeight set to 3008 and maxDestinationWidth set to 3008:

            TransformedBitmap scaledBitmap = new TransformedBitmap();
            if (maxDestinationHeight > 2900 || maxDestinationWidth > 2900)
            {
            RenderOptions.SetBitmapScalingMode(scaledBitmap, BitmapScalingMode.HighQuality);
            }
            scaledBitmap.BeginInit();
            scaledBitmap.Source = bitmapSource;
            scaledBitmap.Transform = new ScaleTransform(scaleFactor, scaleFactor);
            scaledBitmap.EndInit();

            I actually tried all the values that IntelliSense suggested. Besides HighQuality, I also tried Fant (whatever that means), Linear, LowQuality, NearestNeighbor, and the last, Unspecified. All values produce exactly the same artifacts as as my code without an explicit SetBitmapScalingMode. I looked through the other attached properties in RenderOptions and only EdgeMode.Aliased suggested itself, but it also produced exactly the same aliases. Then I tried the following code with all the BitmapScalingMode values, and every one of them produced exactly the same glaring artifacts.

            TransformedBitmap scaledBitmap = new TransformedBitmap();
            scaledBitmap.BeginInit();
            scaledBitmap.Source = bitmapSource;
            scaledBitmap.Transform = new ScaleTransform(scaleFactor, scaleFactor);
            if (maxDestinationHeight > 2900 || maxDestinationWidth > 2900)
            {
            RenderOptions.SetBitmapScalingMode(scaledBitmap.Transform, BitmapScalingMode.HighQuality);
            }
            scaledBitmap.EndInit();

            Hopefully I'm doing something wrong that you can easily spot.

            I Offline
            I Offline
            Insincere Dave
            wrote on last edited by
            #5

            I thought you were applying a RenderTransform to an Image, I didn't know you were working with TransformedBitmap. I haven't been able to reproduce the issue yet. The following for me scales a 4288x4288 px image image as expected:

            JpegBitmapDecoder dec = new JpegBitmapDecoder(new Uri(@"test.jpg"),BitmapCreateOptions.None,BitmapCacheOption.Default);
            var image = dec.Frames[0];
            var targetSize = 2900.0;
            var scale = targetSize/image.PixelWidth;
            TransformedBitmap scaledBitmap = new TransformedBitmap();
            scaledBitmap.BeginInit();
            scaledBitmap.Source = image;
            scaledBitmap.Transform = new ScaleTransform(scale, scale);
            scaledBitmap.EndInit();

            Content = new Image {Width = targetSize,Height = targetSize,Source = scaledBitmap};

            If you could change the code so that it does cause the artifact I'll have another look but you may want to try the MSDN forums as you might get a reply from someone on the WPF team.

            F 1 Reply Last reply
            0
            • I Insincere Dave

              I thought you were applying a RenderTransform to an Image, I didn't know you were working with TransformedBitmap. I haven't been able to reproduce the issue yet. The following for me scales a 4288x4288 px image image as expected:

              JpegBitmapDecoder dec = new JpegBitmapDecoder(new Uri(@"test.jpg"),BitmapCreateOptions.None,BitmapCacheOption.Default);
              var image = dec.Frames[0];
              var targetSize = 2900.0;
              var scale = targetSize/image.PixelWidth;
              TransformedBitmap scaledBitmap = new TransformedBitmap();
              scaledBitmap.BeginInit();
              scaledBitmap.Source = image;
              scaledBitmap.Transform = new ScaleTransform(scale, scale);
              scaledBitmap.EndInit();

              Content = new Image {Width = targetSize,Height = targetSize,Source = scaledBitmap};

              If you could change the code so that it does cause the artifact I'll have another look but you may want to try the MSDN forums as you might get a reply from someone on the WPF team.

              F Offline
              F Offline
              fjparisIII
              wrote on last edited by
              #6

              I thought I said a target size of 2900 would not produce artifacts, so of course you won't see any artifacts. Try a target size of 3008, like my beta tester. Or 2904 for that matter.

              I 1 Reply Last reply
              0
              • F fjparisIII

                I thought I said a target size of 2900 would not produce artifacts, so of course you won't see any artifacts. Try a target size of 3008, like my beta tester. Or 2904 for that matter.

                I Offline
                I Offline
                Insincere Dave
                wrote on last edited by
                #7

                I had already tried 2904,5000 and didn't see anything. You could try forcing software rendering and see if it is a driver issue if not I don't have any more ideas.

                HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

                F 2 Replies Last reply
                0
                • I Insincere Dave

                  I had already tried 2904,5000 and didn't see anything. You could try forcing software rendering and see if it is a driver issue if not I don't have any more ideas.

                  HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                  hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

                  F Offline
                  F Offline
                  fjparisIII
                  wrote on last edited by
                  #8

                  Insincere Dave wrote:

                  I had already tried 2904,5000 and didn't see anything.

                  I tried your code at 3008 and 5000, with my original image at 4288x2848. Resizing to 5000, the artifacts are so horrendous that the original image is barely visible. That same image at 3008 had some barely detectable artifacts, so perhaps you have some extremely simple image that doesn't show the problem. Try a full resolution, digital photograph of people from a modern 12 MPixel DSLR with a variety of colors from clothing and skin tones.

                  Insincere Dave wrote:

                  You could try forcing software rendering and see if it is a driver issue

                  I'm not sure how your example would be used. RenderTargetBitmap also uses software rendering and at least I can get my arms round that. Would that accomplish the same thing you're suggesting? Just a little more background: The original purpose of my scaling function was to provide a batch operation to scale full resolution images straight out of the camera down to a size that can be shown on commonly available monitors 1:1 in a photo viewing application. The batch operation can operate on a single folder or recursively, down a folder tree, so the batch operation can theoretically scale thousands of images with a single mouse click, writing them to another folder tree that mirrors the original, only containing scaled down images. There are no commonly available monitors with resolutions > 2900x2900 and so in my original testing, I never ran across this problem. But one of my beta testers "graduated" from a 6 MPixel digital SLR to a 12 MPixel digital SLR and found working with 3008x3008 images was a lot more convenient than working with 4288x4288 images. So he tried to use my program to perform this scaling. That's how he ran into the problem.

                  1 Reply Last reply
                  0
                  • I Insincere Dave

                    I had already tried 2904,5000 and didn't see anything. You could try forcing software rendering and see if it is a driver issue if not I don't have any more ideas.

                    HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                    hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

                    F Offline
                    F Offline
                    fjparisIII
                    wrote on last edited by
                    #9

                    Insincere Dave wrote:

                    You could try forcing software rendering and see if it is a driver issue

                    I don't know how to use that HwndSource.CompositionTarget.Render mode example you gave. I asked you for an example of how to use it, and you did not respond. But I tried forcing software rendering with the RenderTargetBitmap class and it did not produce the artifacts I'm seeing using the hardware rendering that WPF uses through DirectX. However, the quality of the bitmap rendering was dismal, so it could not be used in a production program for showing photographs. When you say, "to see if it is a driver issue," do you mean a video driver issue? (WPF uses DirectX for all video output and DirectX uses the video driver.) I don't think this is a video driver issue for the following reason. I tried running my program on another machine with completely different video hardware and hence a completely different video driver and I got exactly the same artifacts on all images.

                    Insincere Dave wrote:

                    I had already tried 2904,5000 and didn't see anything.

                    You must be using a very peculiar image. Try a regular photograph of people with colorful clothing and normal skin tones. You'll be sure to see the artifacts. Don't simply scale up a small jpeg to 5000 either, because, as the tests that I've published on this thread show, if you scale a small image up, you can make huge images without producing artifacts. Start with a native JPEG from at least a 6 MPixel camera, take a picture of family or friends, and scale the 3000x2000 image to 5000 and you'll be sure to see the artifacts. They will be so bad you will hardly recognize the original image. The artifacts will completely overlay the entire image, practically obliterating the original. A more practical test would be to scale a 4288W image from a 12 MPixel camera to a 3000W image. That will also surely demonstrate the problem.

                    I 1 Reply Last reply
                    0
                    • F fjparisIII

                      Insincere Dave wrote:

                      You could try forcing software rendering and see if it is a driver issue

                      I don't know how to use that HwndSource.CompositionTarget.Render mode example you gave. I asked you for an example of how to use it, and you did not respond. But I tried forcing software rendering with the RenderTargetBitmap class and it did not produce the artifacts I'm seeing using the hardware rendering that WPF uses through DirectX. However, the quality of the bitmap rendering was dismal, so it could not be used in a production program for showing photographs. When you say, "to see if it is a driver issue," do you mean a video driver issue? (WPF uses DirectX for all video output and DirectX uses the video driver.) I don't think this is a video driver issue for the following reason. I tried running my program on another machine with completely different video hardware and hence a completely different video driver and I got exactly the same artifacts on all images.

                      Insincere Dave wrote:

                      I had already tried 2904,5000 and didn't see anything.

                      You must be using a very peculiar image. Try a regular photograph of people with colorful clothing and normal skin tones. You'll be sure to see the artifacts. Don't simply scale up a small jpeg to 5000 either, because, as the tests that I've published on this thread show, if you scale a small image up, you can make huge images without producing artifacts. Start with a native JPEG from at least a 6 MPixel camera, take a picture of family or friends, and scale the 3000x2000 image to 5000 and you'll be sure to see the artifacts. They will be so bad you will hardly recognize the original image. The artifacts will completely overlay the entire image, practically obliterating the original. A more practical test would be to scale a 4288W image from a 12 MPixel camera to a 3000W image. That will also surely demonstrate the problem.

                      I Offline
                      I Offline
                      Insincere Dave
                      wrote on last edited by
                      #10

                      The software rendering code goes in the loaded event and you apply it to the window, but im not sure it will have any effect if you are just saving the image and not displaying it. I've been working with a high res (5k by 7x) photo and haven't seen anything yet. Im using VS 2010 on vista but have tried targeting both 3.0 and 3.5 and checked they are referencing the correct version. I have also installed the platform update for vista which may have updated the windows imaging component. This thread is the only one i've found that might be applicable but I think you'll have to contact microsoft or try their wpf forums.

                      F 1 Reply Last reply
                      0
                      • I Insincere Dave

                        The software rendering code goes in the loaded event and you apply it to the window, but im not sure it will have any effect if you are just saving the image and not displaying it. I've been working with a high res (5k by 7x) photo and haven't seen anything yet. Im using VS 2010 on vista but have tried targeting both 3.0 and 3.5 and checked they are referencing the correct version. I have also installed the platform update for vista which may have updated the windows imaging component. This thread is the only one i've found that might be applicable but I think you'll have to contact microsoft or try their wpf forums.

                        F Offline
                        F Offline
                        fjparisIII
                        wrote on last edited by
                        #11

                        Insincere Dave wrote:

                        The software rendering code goes in the loaded event and you apply it to the window, but im not sure it will have any effect if you are just saving the image and not displaying it.

                        In my original application, I'm just saving it and not displaying it, but I've written a test application based on code you provided where I just display it and don't save it. I was actually surprised when I saw the bug appear even in this simplified code. I've written the following function, based on code you provided, and this function demonstrates the problem with 100% reliability in 10 different images from my Nikon D2X camera:

                        void ScaleBitmapImage(string imagePath, double targetSize, Image image)
                        {
                        Uri uri = new Uri(imagePath);
                        BitmapImage bitmapImage = new BitmapImage(uri);
                        var scale = targetSize / bitmapImage.PixelWidth;
                        TransformedBitmap scaledBitmap = new TransformedBitmap();
                        scaledBitmap.BeginInit();
                        scaledBitmap.Source = bitmapImage;
                        scaledBitmap.Transform = new ScaleTransform(scale, scale);
                        scaledBitmap.EndInit();
                        image.Source = scaledBitmap;
                        }

                        Insincere Dave wrote:

                        Im using VS 2010 on vista

                        I'm using VS 2008 on Vista, but I have installed VS 2010. I just haven't gotten around to trying it out yet on 2010. Maybe I should try that next.

                        Insincere Dave wrote:

                        I have also installed the platform update for vista which may have updated the windows imaging component.

                        I've been Googling around trying to figure out how to download this update and I haven't found anything definitive. I've seen plenty of references to it but no specific link to a download page. I followed Microsoft's instructions at this link: http://support.microsoft.com/kb/971644[^] But when I follow the instructions, the closest thing it lists in the Windows Update List is an item called, "Update for Windows Vista for x64-based systems - English (KB937286)". Hopefully that is the same thing as the Platform Update for Vista. I'm about to do that now, which of course means rebooting my machine. I'll let you know how things turn out. I'd love to be able to tell my customers what needs to be done to solve this horrendous bug.

                        F 1 Reply Last reply
                        0
                        • F fjparisIII

                          Insincere Dave wrote:

                          The software rendering code goes in the loaded event and you apply it to the window, but im not sure it will have any effect if you are just saving the image and not displaying it.

                          In my original application, I'm just saving it and not displaying it, but I've written a test application based on code you provided where I just display it and don't save it. I was actually surprised when I saw the bug appear even in this simplified code. I've written the following function, based on code you provided, and this function demonstrates the problem with 100% reliability in 10 different images from my Nikon D2X camera:

                          void ScaleBitmapImage(string imagePath, double targetSize, Image image)
                          {
                          Uri uri = new Uri(imagePath);
                          BitmapImage bitmapImage = new BitmapImage(uri);
                          var scale = targetSize / bitmapImage.PixelWidth;
                          TransformedBitmap scaledBitmap = new TransformedBitmap();
                          scaledBitmap.BeginInit();
                          scaledBitmap.Source = bitmapImage;
                          scaledBitmap.Transform = new ScaleTransform(scale, scale);
                          scaledBitmap.EndInit();
                          image.Source = scaledBitmap;
                          }

                          Insincere Dave wrote:

                          Im using VS 2010 on vista

                          I'm using VS 2008 on Vista, but I have installed VS 2010. I just haven't gotten around to trying it out yet on 2010. Maybe I should try that next.

                          Insincere Dave wrote:

                          I have also installed the platform update for vista which may have updated the windows imaging component.

                          I've been Googling around trying to figure out how to download this update and I haven't found anything definitive. I've seen plenty of references to it but no specific link to a download page. I followed Microsoft's instructions at this link: http://support.microsoft.com/kb/971644[^] But when I follow the instructions, the closest thing it lists in the Windows Update List is an item called, "Update for Windows Vista for x64-based systems - English (KB937286)". Hopefully that is the same thing as the Platform Update for Vista. I'm about to do that now, which of course means rebooting my machine. I'll let you know how things turn out. I'd love to be able to tell my customers what needs to be done to solve this horrendous bug.

                          F Offline
                          F Offline
                          fjparisIII
                          wrote on last edited by
                          #12

                          Well, that update I mentioned (KB937286) wasn't the Platform Update for Vista, but something that just came out today. Also, VS 2010 doesn't solve the problem. I converted my little application to VS 2010 and the problem still shows up. I guess I'll have to keep searching for the download page for the Platform Update for Vista. I don't know why the Microsoft download page doesn't show up when I Google for it, only a bunch of pages that mention that it's been released, and I haven't found any of those pages giving the link to the download page.

                          I 1 Reply Last reply
                          0
                          • F fjparisIII

                            Well, that update I mentioned (KB937286) wasn't the Platform Update for Vista, but something that just came out today. Also, VS 2010 doesn't solve the problem. I converted my little application to VS 2010 and the problem still shows up. I guess I'll have to keep searching for the download page for the Platform Update for Vista. I don't know why the Microsoft download page doesn't show up when I Google for it, only a bunch of pages that mention that it's been released, and I haven't found any of those pages giving the link to the download page.

                            I Offline
                            I Offline
                            Insincere Dave
                            wrote on last edited by
                            #13

                            http://support.microsoft.com/kb/971644[^] Says you use windows update to get it.

                            F 1 Reply Last reply
                            0
                            • I Insincere Dave

                              http://support.microsoft.com/kb/971644[^] Says you use windows update to get it.

                              F Offline
                              F Offline
                              fjparisIII
                              wrote on last edited by
                              #14

                              Yes, I found that link and followed the instructions. I didn't find a reference to the Platform Update for Vista. So I investigated further and saw that before the Platform Update can be installed, you have to have Vista SP2 installed, which I didn't! As I type, it is ready to be installed. After it gets installed, 971644 will hopefully show the Platform Update available for installation. Right now I have to shut everything down before the SP2 installation will start!

                              F 1 Reply Last reply
                              0
                              • F fjparisIII

                                Yes, I found that link and followed the instructions. I didn't find a reference to the Platform Update for Vista. So I investigated further and saw that before the Platform Update can be installed, you have to have Vista SP2 installed, which I didn't! As I type, it is ready to be installed. After it gets installed, 971644 will hopefully show the Platform Update available for installation. Right now I have to shut everything down before the SP2 installation will start!

                                F Offline
                                F Offline
                                fjparisIII
                                wrote on last edited by
                                #15

                                Incredible! Getting the Platform Update for Vista installed did the trick! Thank you so much for sticking with me! So this is probably not a problem under Windows 7, and I don't think there's a fix for it under XP. I'll have to document that in my application.

                                I 1 Reply Last reply
                                0
                                • F fjparisIII

                                  Incredible! Getting the Platform Update for Vista installed did the trick! Thank you so much for sticking with me! So this is probably not a problem under Windows 7, and I don't think there's a fix for it under XP. I'll have to document that in my application.

                                  I Offline
                                  I Offline
                                  Insincere Dave
                                  wrote on last edited by
                                  #16

                                  Im glad that fixed it, I thought that was kind of a long shot really. I tried scaling an Image control and using RenderTargetBitmap and didn't notice any quality degradation so that might be a workaround for xp, there are some other options like System.Drawing aswell.

                                  F 1 Reply Last reply
                                  0
                                  • I Insincere Dave

                                    Im glad that fixed it, I thought that was kind of a long shot really. I tried scaling an Image control and using RenderTargetBitmap and didn't notice any quality degradation so that might be a workaround for xp, there are some other options like System.Drawing aswell.

                                    F Offline
                                    F Offline
                                    fjparisIII
                                    wrote on last edited by
                                    #17

                                    Insincere Dave wrote:

                                    I tried scaling an Image control and using RenderTargetBitmap and didn't notice any quality degradation

                                    I'm probably doing something wrong. Is your code small enough to quote here so I can see how you did this?

                                    I 1 Reply Last reply
                                    0
                                    • F fjparisIII

                                      Insincere Dave wrote:

                                      I tried scaling an Image control and using RenderTargetBitmap and didn't notice any quality degradation

                                      I'm probably doing something wrong. Is your code small enough to quote here so I can see how you did this?

                                      I Offline
                                      I Offline
                                      Insincere Dave
                                      wrote on last edited by
                                      #18

                                      There is a recent update for WIC for xp that might contain the fix. This code might still cause the artifact you could try setting the BitmapScalingMode if it does.

                                      void ScaleUsingRTB(string inFile, string outFile, double scale)
                                      {
                                      Uri uri = new Uri(inFile);
                                      BitmapImage bitmapImage = new BitmapImage(uri);
                                      var image = new Image
                                      {
                                      Source = bitmapImage, Width = bitmapImage.PixelWidth*scale, Height = bitmapImage.PixelHeight*scale
                                      };
                                      image.Measure(new Size(image.Width,image.Height));
                                      image.Arrange(new Rect(0,0,image.Width,image.Height));
                                      RenderTargetBitmap rtb = new RenderTargetBitmap((int) image.Width, (int) image.Height, 96, 96, PixelFormats.Pbgra32);
                                      rtb.Render(image);

                                      Save(outFile,rtb);
                                      

                                      }

                                      F 1 Reply Last reply
                                      0
                                      • I Insincere Dave

                                        There is a recent update for WIC for xp that might contain the fix. This code might still cause the artifact you could try setting the BitmapScalingMode if it does.

                                        void ScaleUsingRTB(string inFile, string outFile, double scale)
                                        {
                                        Uri uri = new Uri(inFile);
                                        BitmapImage bitmapImage = new BitmapImage(uri);
                                        var image = new Image
                                        {
                                        Source = bitmapImage, Width = bitmapImage.PixelWidth*scale, Height = bitmapImage.PixelHeight*scale
                                        };
                                        image.Measure(new Size(image.Width,image.Height));
                                        image.Arrange(new Rect(0,0,image.Width,image.Height));
                                        RenderTargetBitmap rtb = new RenderTargetBitmap((int) image.Width, (int) image.Height, 96, 96, PixelFormats.Pbgra32);
                                        rtb.Render(image);

                                        Save(outFile,rtb);
                                        

                                        }

                                        F Offline
                                        F Offline
                                        fjparisIII
                                        wrote on last edited by
                                        #19

                                        The code you supplied does work and at least superficially (without "pixel-peeping") provides good quality. Of course the following line does not compile:

                                        Insincere Dave wrote:

                                        Save(outFile,rtb);

                                        but can be replaced with code that does and the scaled image file does not contain artifacts, even on an XP system. In Googling, I was surprised by how many people can't get RenderTargetBitmap to work, complaining of blank images. I tried some of the code posted that supposedly works and I also got blank images, and solutions posted that supposedly fixed the blank images did not work. But your code works, and I never saw anyone post that solution. Where did you get it, or did you just figure it out? The code I've seen posted is also considerably more complicated than what you posted. In any case, I now have software rendering code that I can use for XP systems and Vista systems not up to SP2. Once again, thank you very much. I'm not even going to try the WIC solution because I don't want to contaminate my application with COM code.

                                        I 1 Reply Last reply
                                        0
                                        • F fjparisIII

                                          The code you supplied does work and at least superficially (without "pixel-peeping") provides good quality. Of course the following line does not compile:

                                          Insincere Dave wrote:

                                          Save(outFile,rtb);

                                          but can be replaced with code that does and the scaled image file does not contain artifacts, even on an XP system. In Googling, I was surprised by how many people can't get RenderTargetBitmap to work, complaining of blank images. I tried some of the code posted that supposedly works and I also got blank images, and solutions posted that supposedly fixed the blank images did not work. But your code works, and I never saw anyone post that solution. Where did you get it, or did you just figure it out? The code I've seen posted is also considerably more complicated than what you posted. In any case, I now have software rendering code that I can use for XP systems and Vista systems not up to SP2. Once again, thank you very much. I'm not even going to try the WIC solution because I don't want to contaminate my application with COM code.

                                          I Offline
                                          I Offline
                                          Insincere Dave
                                          wrote on last edited by
                                          #20

                                          I can't remember where I first saw code using RenderTargetBitmap, you need to call measure and arrange if the item hasn't been added to the visual tree otherwise it's not necessary. WPF uses WIC so that patch might still be applicable but I don't know if it will fix the issue.

                                          F 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups