Rotate an image in Windows Phone

Hi guys, I am showing a photo that I took on one of my pages.

I take a photo in portrait mode and it works fine.

When I show a picture in the following image, it processes the photo as it was taken in Landscape.

So I need to rotate the image / image by -90 to fix this.

Here is the relevant code for my .XAML

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanelx" Grid.Row="1" Margin="0,0,0,0">
    </Grid>

And here are the methods in which I upload a photo and put it in a ContentPanel.

void loadImage () {// The image will be read from the isolated storage to the next byte array

        byte[] data;

        // Read the entire image in one go into a byte array

        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
        {

            // Open the file - error handling omitted for brevity

            // Note: If the image does not exist in isolated storage the following exception will be generated:

            // System.IO.IsolatedStorage.IsolatedStorageException was unhandled 

            // Message=Operation not permitted on IsolatedStorageFileStream 

            using (IsolatedStorageFileStream isfs = isf.OpenFile("0.jpg", FileMode.Open, FileAccess.Read))
            {

                // Allocate an array large enough for the entire file

                data = new byte[isfs.Length];



                // Read the entire file and then close it

                isfs.Read(data, 0, data.Length);

                isfs.Close();

            }
        }



        // Create memory stream and bitmap

        MemoryStream ms = new MemoryStream(data);

        BitmapImage bi = new BitmapImage();

        // Set bitmap source to memory stream

        bi.SetSource(ms);

        // Create an image UI element – Note: this could be declared in the XAML instead

        Image image = new Image();

        // Set size of image to bitmap size for this demonstration

        image.Height = bi.PixelHeight;

        image.Width = bi.PixelWidth;

        // Assign the bitmap image to the image’s source

        image.Source = bi;

        // Add the image to the grid in order to display the bit map

        ContentPanelx.Children.Add(image);

    }
}

I think that just rotate on the image after loading. I can do it in iOS, but my C # skills are worse than bad.

Can anyone advise this?

Thanks a lot, -Cake

+3
2

xaml, :

//XAML
    <Image.RenderTransform>     
    <RotateTransform Angle="90" /> 
      </Image.RenderTransform>

#. , xaml optioin

//C#
((RotateTransform)image.RenderTransform).Angle = angle;

:

RotateTransform rt = new RotateTransform();
            rt.Angle = 90;

            image.RenderTransform = rt;
+7

RotateTransform, RenderTransform . WPF Image .

, , :

RotateTransform rt = new RotateTransform();
rt.Angle = 90;
image.RenderTransform = rt;
image.RenderTransformOrigin = new Point(0.5, 0.5);
-1

All Articles