.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
Anonymous
May 26, 2010
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 48x48 RTB, and the Image that displays it is also 48x48, 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, EricAnonymous
May 28, 2010
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.Anonymous
June 01, 2010
@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.Anonymous
June 03, 2010
@wpf3d: All the idea is to put 3d in browser/xbap. But D3Dimage requires full trust.Anonymous
June 04, 2010
The comment has been removedAnonymous
June 07, 2011
Hey there! Is this blog dead? Are there any upcoming changes to WPF 3D?Anonymous
August 26, 2013
PErfect