2

I tried following code to rotate image on button click event,

if (btn.Text.Equals("Rotate"))
{
    if (angle >= 360)
        angle = 0;

    angle += 90;
    RotateTransform rt = new RotateTransform();
    rt.Angle = angle;
    img.RenderTransform = rt;       
}

using above code image get rotated 90 degree in addition to previous rotation on button click.

I want to save that rotated image using WritableBitmap. How can I save it?

Wosi
  • 41,986
  • 17
  • 75
  • 82
Chetan Mahajan
  • 388
  • 2
  • 15
  • Something like this? [Save image to phone storage](http://stackoverflow.com/a/19793769/2596334) – Scott Solmer Oct 27 '15 at 12:28
  • @Okuma.Scott I tried code from the link you suggested but i get error for (img.Source as BitmapImage).GetStream(); method GetStream() for BitmapImage not found. – Chetan Mahajan Oct 27 '15 at 12:41

1 Answers1

1

I tried following steps and it worked for saving rotated image with WritableBitmap,

Step 1) Placed Image control inside StackPanel control as mentioned below,

    <StackPanel x:Name="ContentPanel" Grid.Row="1" Background="Black" Height="400" Width="400"  Margin="0, 50, 0, 50" >
    <Image x:Name="img" RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache" Grid.Row="1" Stretch="UniformToFill" Height="400" Width="400" >
         <Image.RenderTransform>
             <CompositeTransform x:Name="transform" />
         </Image.RenderTransform> 
    </Image>
</StackPanel>

Step 2) Used following code to save WitableBitmap using StackPanel "ContentPanel" as I added Image control on ContentPanel,

IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

if (isolatedStorage.FileExists(filePath))
   isolatedStorage.DeleteFile(filePath);

var fileStream = isolatedStorage.CreateFile(filePath);

WriteableBitmap wb = new WriteableBitmap(ContentPanel, null);

wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);

fileStream.Close();
Chetan Mahajan
  • 388
  • 2
  • 15