Skip to content

Instantly share code, notes, and snippets.

@Spraynard
Last active February 14, 2019 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spraynard/7bc3e55dac964bff210d512a4898db6b to your computer and use it in GitHub Desktop.
Save Spraynard/7bc3e55dac964bff210d512a4898db6b to your computer and use it in GitHub Desktop.
Rotate images in a flow document by rotating the control type
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
...
FileInfo imgInfo = new FileInfo(path_to_img)
// Create rotate transform that will be applied to our image.
RotateTransform transform = new RotateTransform(90); // 90-degree rotation transform.
// Control type
Image myImage = new Image();
BitmapImage bitmapImg = new BitmapImage();
bitmapImg.BeginInit()
bitmap.uriSource = new Uri(imgInfo.FullName);
bitmap.EndInit();
myImage.Source = bitmapImg;
// Changing our rotation transform's origin from top left to center of image
transform.CenterX = myImage.ActualWidth / 2;
transform.CenterY = myImage.ActualHeight / 2;
// Applying transform on image control
myImage.RenderTransform = transform;
// Create our BlockUIContainer
BlockUIContainer container = new BlockUIContainer();
container.Child = myImage;
// Insert container with image into the document.
FlowDocument doc = new FlowDocument();
doc.Blocks.Add(container);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment