Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Vertically Flip an BitmapImage

Tags:

c#

wpf

I want to Flip an BitmapImage vertically as an a mirror image of the original. This what I have but it Rotates not flips an image.

var tb = new TransformedBitmap();
BitmapImage bi = Type.Image.Clone();
tb.BeginInit();
tb.Source = bi;
var transform = new RotateTransform(180);
tb.Transform = transform;
tb.EndInit();
like image 402
Taufiq Abdur Rahman Avatar asked Nov 04 '13 07:11

Taufiq Abdur Rahman


People also ask

How do you flip something vertically?

Right click on that object, and select 'Flip Horizontal' or 'Flip Vertical'.

How do you flip and image vertically?

Click the object that you want to rotate. Under Drawing Tools (or Picture Tools if you're rotating a picture), on the Format tab, in the Arrange group, click Rotate, and then: To turn an object upside-down, click Flip Vertical.


1 Answers

You should use scaleTransform, not Rotate. And set its y scale to -1 to set it as mirror:

var transform = new ScaleTransform(1, -1, 0, 0);

See http://msdn.microsoft.com/en-us/library/aa348048.aspx

like image 191
Alex Avatar answered Sep 19 '22 06:09

Alex