Gourav Singhal

Gourav Singhal

  • NA
  • 42
  • 26.7k

How to convert Xaml Image to WriteableBitmap after rotation?

Sep 14 2017 11:00 PM
I have created an Xaml "Image" object programatically from byte array & set its width, height, alignments. Setting width & height is important as I am fitting small image in bigger writableBitmap & aligning it in Center too.
 
  1. Image img = new Image();  
  2. img.Height = x;  
  3. img.Width = y;  
  4. img.Source = inSource;  
  5. img.HorizontalAlignment = HorizontalAlignment.Center;  

In Phone 8.0, I did:

  1. RotateTransform transform = new RotateTransform();  
  2. WritableBitmap bitmap = new WriteableBitmap(img, transform);// I want this step in UWP. How to do?  
 

But, In UWP I am stuck as this writableBitmap constructor is not there where I can apply transformation on UI element like Image. I hope I am clear in my query. Please suggest me the way I can do this.

What I have tried: I have moved the WritableBitmap to bigger Writablebitmap aligning it to center(using Maths). Then using WriteBitmapEx, rotating the image to x angle (75, 45 etc.). But it is corrupting the image.

Any help will be appreciated.