在旋转的Windows Phone图像 [英] Rotating an Image in Windows Phone

查看:103
本文介绍了在旋转的Windows Phone图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我展示的照片我把我的网页之一。



我捕捉人像模式中的照片,它工作正常。



当我告诉我的下一个视图画面它把喜欢的照片拍摄于风景。



所以我需要旋转图片由-90 /图像纠正。



下面是我的.XAML



<$ p $的相关代码p> <! - 的ContentPanel - 在这里放置其他内容 - >
<电网X:NAME =ContentPanelxGrid.Row =1保证金=0,0,0,0>
< /网格和GT;

和这里是我加载照片并把它放入的ContentPanel。

方法

无效的LoadImage()
{
//图像将被从孤立的存储读取到以下字节数组

 字节[]数据; 

//读取整个图像中的一个进入的字节数组

使用(IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
{

//打开文件 - 处理不再赘述

//注意的错误:

:如果图像不出现以下异常会产生孤立存在的存储// System.IO.IsolatedStorage.IsolatedStorageException了未处理

//消息=不IsolatedStorageFileStream

使用(IsolatedStorageFileStream ISFS = isf.OpenFile(0.jpg允许操作,FileMode.Open,FileAccess.Read))
{

//分配足够大,整个文件

数据=新的字节[数组isfs.Length ];



//读取整个文件,然后将其关闭

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

isfs.Close();

}
}



//创建内存流和位图

的MemoryStream毫秒=新的MemoryStream (数据);

BitmapImage的双向=新的BitmapImage();

//设置位图源内存流

bi.SetSource(毫秒);

//创建一个图像用户界面元素 - 注意:这可能在XAML中声明,而不是

图像形象=新的图像();图像

//设置大小为位图大小此演示

image.Height = bi.PixelHeight;

image.Width = bi.PixelWidth;

//将位图图像输出到图像的源

image.Source =双向;

//图像添加到网格以便显示位映像

ContentPanelx.Children.Add(图像);

}
}



我觉得在一个简单的循环图像后,我已经加载这一点。我能做到这一点的iOS,但我的C#是技能,比坏的更坏。



任何人都可以提出建议吗?



非常感谢,
-Cake


解决方案

如果图像在XAML中声明你可以像这样旋转:

  // XAML 
< Image.RenderTransform>
< RotateTransform角=90/>
< /Image.RenderTransform>



同样的事情可以直通C#也可以做。如果你总是旋转的图像,然后doint它在XAML是optioin

  // C#
((RotateTransform越好)image.RenderTransform).Angle =角;

请试试这个:

  RotateTransform RT =新RotateTransform(); 
rt.Angle = 90;

image.RenderTransform = RT;


Hi guys I display a photo I took on one of my pages.

I capture the photo in Portrait mode and it works ok.

When I show the picture on my next view it treats the photo like it was taken in Landscape.

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

Here is the relevant code of my .XAML

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

And here is the methods where I load the photo and put it into the ContentPanel.

void loadImage() { // The image will be read from isolated storage into the following 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 a simple rotate on the image after I've loaded this. I can do this in iOS but my C# is skills are worse than bad.

Can anybody advise on this ?

Many Thanks, -Cake

解决方案

If the image is declared in xaml you can rotate it like this:

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

Same thing can be done thru c# also. If you always rotate the image , then doint it in xaml is the better optioin

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

Please try this one:

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

            image.RenderTransform = rt;

这篇关于在旋转的Windows Phone图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆