.NET 4.0 Image Scaling Change Reminder


As we mentioned earlier in this blog post, the default BitmapScalingMode has changed from Fant to Linear. If you compile your app for 4.0 and notice scaled bitmaps looking worse, this is why. If you want the old look, set the mode back to Fant.

Fant produces the best looking scaled bitmap but the scaling is done on the CPU at certain intervals. This CPU usage can make your scale animations stutter. On the other hand, Linear is done entirely by the GPU so everything is smooth but the quality suffers. Linear may also use more video memory than Fant but that depends on the scenario.

— Jordan

Comments (7)

  1. Eric says:

    But how do I set the BitmapScalingMode to Fant in when I am creating a RenderTargetBitmap (RTB)?  I have *not* been able to get my bitmaps created this way to look good since moving to .NET 4.  My code looks like this:

    Visual clientPanel = VCFinder.FindVisualChildByName<Visual>( visual, "m_ClientPanel" );

    int width = -1;

    bool rc = int.TryParse( ( string )param, out width );

    if ( width > 0 )

    {

      DrawingVisual dv = new DrawingVisual();

      RenderOptions.SetBitmapScalingMode(dv, BitmapScalingMode.Fant);

      using (DrawingContext ctx = dv.RenderOpen())

      {

         VisualBrush vb;

         if ( clientPanel != null )

            vb = new VisualBrush( clientPanel );

         else

            vb = new VisualBrush( ( Visual )value );

         vb.Stretch = Stretch.UniformToFill;

         vb.AlignmentX = AlignmentX.Left;

         vb.AlignmentY = AlignmentY.Top;

         RenderOptions.SetBitmapScalingMode(vb, BitmapScalingMode.Fant);

         ctx.DrawRectangle(vb, null, new Rect(0, 0, (double)width, (double)width));

      }

      RenderTargetBitmap rtb = new RenderTargetBitmap( width, width, 96.0, 96.0, PixelFormats.Pbgra32 );

      RenderOptions.SetBitmapScalingMode(rtb, BitmapScalingMode.Fant);

      rtb.Render( dv );

      return rtb;

    }

    So there are 3 places in here that I've tried setting BitmapScalingMode to Fant, to no avail.  I also set BitmapScalingMode to Fant on the Image that this RTB gets displayed in, and that doesn't help either.  But this routine creates a 48×48 RTB, and the Image that displays it is also 48×48, so the Image would not need to do any scaling.  I need the scaling that creates the RTB to use Fant, which it apparently used to do, but now it doesn't, and I don't seem to be able to make it do it.  How do I solve this?

    Thanks,

    Eric

  2. HisStar says:

    Sorry for offtopic, but is there any way to realize hardware accelerated mesh animation like in DX in future?

    I am surprised why this has not been yet done. Animation is 90% of requirements and success.

  3. zer0mus says:

    @Eric: RenderOptions don't work on every object. It's one of the… upsides to attached properties :). BitmapScalingMode needs to be set on a UIElement or, I think, DrawingGroup. It inherits.

    @HisStar: Who knows what the future holds but for now you can use D3DImage if you need it.

  4. HisStar says:

    @wpf3d: All the idea is to put 3d in browser/xbap. But D3Dimage requires full trust.

  5. Eric says:

    @wpf3d: Thanks for the response.  So, in my code snippet, what object do I need to set BitmapScalingMode on so that the RenderTargetBitmap that I end up with is scaled like it was in Visual Studio 2008?  Or is there some other property I need to set since these objects are not UIElements? That's really the issue:  Whatever is doing the scaling in that snippet decided to start using lower quality scaling in .NET 4, and I cannot find an incantation that will convince it to go back to high quality scaling.

    Eric

  6. Gogo says:

    Hey there! Is this blog dead? Are there any upcoming changes to WPF 3D?

Skip to main content