none
Flipping an Image or other UIElement without PlaneProjection or pixel shaders.

    Question

  •  By flip I don't mean rotate 180 degrees, I mean mirror.  Is there a performant way to do this?

    Tuesday, March 31, 2009 7:49 PM

Answers

  • Since scaling is GPU Accelerated, what about using a negative ScaleX or ScaleY to get the mirror effect?

    Something like...

    <ScaleTransform ScaleY="-1" />

    or

    <ScaleTransform ScaleX="-1" />

    Wednesday, April 01, 2009 8:01 AM

All replies

  • Hi,

    I think you can do this with a RenderTransform Matrix, like this:

    <Image Source="MyImage.jpg" Stretch="None" RenderTransformOrigin="0.5,0.5">
        <Image.RenderTransform>
            <MatrixTransform Matrix="1,0,0,-1,0,0" />
        </Image.RenderTransform>
    </Image>
    Tuesday, March 31, 2009 8:12 PM
  •  Thanks, but I should have mentioned that I'm looking for a method that supports GPU acceleration, if one exists.  It seems that using a MatrixTransform as you suggested causes the image to disappear altogether when GPU acceleration is on.

    Tuesday, March 31, 2009 8:58 PM
  • I think then the only solution is PlaneProjection which as far as I know is hardware accelerated.
    Wednesday, April 01, 2009 12:19 AM
  • Hm, I am pretty sure Seema said PlaneProjections are not hardware accelerated in one of her MIX presentations.  If MatrixTransforms are not accelerated, then why would projections be?  Still I'll give it a look just to make sure.  Thanks for the suggestions.  :).

    Wednesday, April 01, 2009 2:07 AM
  • Your probably right, theres lots of conflicting posts out there.

    At least these kind of things can be hardware accelerated in the future when Silverlight 3 gets to RTW.

    3D Games have been using hardware acceleration for 3D rendering for the last 15 years so Silverlight will eventually get it right (Microsoft can answer this)?
    Wednesday, April 01, 2009 2:25 AM
  • Yeah it's hard these days to figure out whats GPU accelerated and whats not. Here are some links that might help you, as I can't at the moment :)

    http://www.wintellect.com/CS/blogs/jprosise/archive/2009/03/29/silverlight-3-s-new-gpu-acceleration.aspx

    http://www.andybeaulieu.com/Home/tabid/67/EntryID/144/Default.aspx
    See the comments on this one also as Andy explains a little more there.

    http://videos.visitmix.com/MIX09/T17F

    Hope it helps :)

    Wednesday, April 01, 2009 2:45 AM
  • Since scaling is GPU Accelerated, what about using a negative ScaleX or ScaleY to get the mirror effect?

    Something like...

    <ScaleTransform ScaleY="-1" />

    or

    <ScaleTransform ScaleX="-1" />

    Wednesday, April 01, 2009 8:01 AM
  •  Andy, that is an excellent suggestion, and it also appears to be exactly what Blend does to flip elements (I forgot the option exists).  Maddeningly, this transformation does not work with GPU Acceleration!  It is possible to do a 180 degree rotation by setting both ScaleY and ScaleX to -1, but if you set just one, the UIElement disappears.  Argh!  I'm tempted to file this as a bug, since at the very least, it should be falling back to software rendering rather than causing the element to vanish, but ideally they should make this possible with GPU acceleration.  I believe it's completely trivial to do in hardware.

    Wednesday, April 01, 2009 12:57 PM
  • Wow, you're right - I was able to reproduce the same behavior. Definitely looks like a bug.

    Wednesday, April 01, 2009 3:40 PM
  •  Andy, thanks for confirming.  I posted a thread on the issue in the "Report a Bug" section. 

    Wednesday, April 01, 2009 5:28 PM