Rotating Shapes with a BitmapEffect (known problem since Jan. 2008)
- I´m looking for a solution for the old known problem for rotating any shape object (e.g. polygon) with a BitmapEffect. At around 90 till 270 degrees the shape get lost or get very strange appearances. Exists there any bugfix or solution from microsoft right now or exists for that any moderate workaround.
This issue is known also here in the MSDN forum since Jan. 2008 but so far there was no big response from the microsoft team directly. Does anybode of you have a guess? See also: Rotating a Polygon with a BitmapEffect. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/cfda9fa2-df1e-47cf-8781-6759ec9d0b1e/
Kind regards,
maex
<Window x:Class="WpfApplication2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="800" Width="800"> <Grid Background="Yellow"> <Canvas x:Name="Canvas" Margin="100" Background="Lavender"> <Polyline x:Name="MainPolyline" Points="25,25 0,50 25,75 50,50 25,25 25,0" Stroke="Black" StrokeThickness="10" Canvas.Left="250" Canvas.Top="250"> <Polyline.BitmapEffect> <OuterGlowBitmapEffect GlowColor="Blue" GlowSize="30" Opacity="0.4"></OuterGlowBitmapEffect> </Polyline.BitmapEffect> </Polyline> <Button Margin="400" Click="Button5_Click">Change Angle + 30°</Button> </Canvas> </Grid> </Window> using System.Windows; using System.Windows.Media; namespace WpfApplication2 { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private double currentAngle = 0; private void Button5_Click(object sender, RoutedEventArgs e) { if (currentAngle > 350) currentAngle = 0; else currentAngle += 30; MainPolyline.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform1 = new RotateTransform(currentAngle); MainPolyline.RenderTransform = rotateTransform1; } } }
Answers
This is a known issue that was not fixed. Applying a rotation to live content with BitmapEffects causes clipping problems because the bounds are calculated incorrectly. The best advice I have for you is to try and create a bitmap copy of your Polygon with its BitmapEffect (using RenderTargetBitmap) and then apply the rotation to the resulting bitmap.
I should also note that BitmapEffects were marked as deprecated in 3.5 SP1 and support for them was cut for .Net 4.0. They had a number of issues (mostly performance related) that drove this decision - the recommended alternatives are the hardware-accelerated Effects introduced in 3.5 SP1.- Proposed As Answer byBrendan Clark - MSFT Wednesday, November 04, 2009 2:20 AM
- Marked As Answer byBruce.ZhouMSFT, ModeratorMonday, November 09, 2009 8:24 AM
All Replies
This is a known issue that was not fixed. Applying a rotation to live content with BitmapEffects causes clipping problems because the bounds are calculated incorrectly. The best advice I have for you is to try and create a bitmap copy of your Polygon with its BitmapEffect (using RenderTargetBitmap) and then apply the rotation to the resulting bitmap.
I should also note that BitmapEffects were marked as deprecated in 3.5 SP1 and support for them was cut for .Net 4.0. They had a number of issues (mostly performance related) that drove this decision - the recommended alternatives are the hardware-accelerated Effects introduced in 3.5 SP1.- Proposed As Answer byBrendan Clark - MSFT Wednesday, November 04, 2009 2:20 AM
- Marked As Answer byBruce.ZhouMSFT, ModeratorMonday, November 09, 2009 8:24 AM
Thank you for the information. So we completly get rid of using the OuterGlowBitmapEffect for shapes. But instead we found a other solution for out problem, which was to use instead the DropShadowEffect. This does work also when rotating.
E.g.
<DropShadowEffect ShadowDepth="0" Color="DodgerBlue" Opacity="1.0" BlurRadius="8"/>
- Yes, the hardware-accelerated Effects classes do not have the same problem that the deprecated BitmapEffects did.


