Поворот изображения в Windows Phone
Привет, ребята, я показываю фотографию, которую я сделал на одной из моих страниц.
Я делаю снимок в портретном режиме, и он работает нормально.
Когда я показываю снимок на следующем снимке, он обрабатывает снимок так, как будто он был сделан в альбомной ориентации.
Поэтому мне нужно повернуть картинку / изображение на -90, чтобы исправить это.
Вот соответствующий код моего.XAML
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanelx" Grid.Row="1" Margin="0,0,0,0">
</Grid>
А вот методы, с помощью которых я загружаю фотографию и помещаю ее в ContentPanel.
void loadImage () {// Изображение будет считано из изолированного хранилища в следующий байтовый массив
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);
}
}
Я думаю, что простой поворот изображения после того, как я загрузил это. Я могу сделать это в iOS, но мои навыки на C# хуже, чем плохие.
Кто-нибудь может посоветовать это?
Большое спасибо, торт
2 ответа
Если изображение объявлено в xaml, вы можете повернуть его так:
//XAML
<Image.RenderTransform>
<RotateTransform Angle="90" />
</Image.RenderTransform>
То же самое можно сделать и через C#. Если вы всегда поворачиваете изображение, лучше использовать его в xaml.
//C#
((RotateTransform)image.RenderTransform).Angle = angle;
Примерьте вот это:
RotateTransform rt = new RotateTransform();
rt.Angle = 90;
image.RenderTransform = rt;
Вы можете создать объект RotateTransform, чтобы использовать его для свойства RenderTransform изображения. Это заставит WPF поворачивать элемент управления Image при рендеринге.
Если вы хотите повернуть изображение вокруг его центра, вам также необходимо установить начало вращения, как показано ниже:
RotateTransform rt = new RotateTransform();
rt.Angle = 90;
image.RenderTransform = rt;
image.RenderTransformOrigin = new Point(0.5, 0.5);