Writeablebitmap.SaveJpeg 正在将我的图像旋转 -90 度

发布于 2024-11-05 06:52:57 字数 931 浏览 1 评论 0原文

我使用以下代码从手机上的 MediaLibrary 获取图片并调整其大小。在模拟器中,它工作正常,但当我在真实手机上尝试时,它会旋转 -90 度。

SaveJpeg 的第四个参数是方向,工具提示显示 “此方法当前未使用此参数。使用值 0 作为占位符。”

如果我通过 0,1,-1,也会发生同样的事情。看起来它实际上可能在手机上实现,而不是在模拟器中实现,但我不知道要传递什么。

public byte[] GetPhoto(string photoName, int width, int height)
    {
        using (var ml = new Microsoft.Xna.Framework.Media.MediaLibrary())
        {
            using(Stream stream = (from p in ml.Pictures where p.Name == photoName select p).FirstOrDefault().GetImage())
            {
                //load the stream into a WriteableBitmap so it can be resized
                using(MemoryStream outstream = new MemoryStream())
                {
                    PictureDecoder.DecodeJpeg(stream).SaveJpeg(outstream, width, height, 0, 85);
                    return outstream.ToArray();
                }
            }
        }
    }

另外我刚刚注意到手机上的样本照片没有这个问题,只有我拍摄的照片有这个问题。

I'm using the following code to get a picture from the the MediaLibrary on the phone and resize it. In the emulator it is working fine but it is rotating it -90 degrees when I try it on a real phone.

The 4th parameter for SaveJpeg is orientation and the tooltip says
"This parameter is not currently used by this method. Use a value of 0 as a placeholder."

The same thing happens if I pass 0,1,-1. Seems like it might actually be implemented on the phone and not in the emulator, but I don't know what to pass.

public byte[] GetPhoto(string photoName, int width, int height)
    {
        using (var ml = new Microsoft.Xna.Framework.Media.MediaLibrary())
        {
            using(Stream stream = (from p in ml.Pictures where p.Name == photoName select p).FirstOrDefault().GetImage())
            {
                //load the stream into a WriteableBitmap so it can be resized
                using(MemoryStream outstream = new MemoryStream())
                {
                    PictureDecoder.DecodeJpeg(stream).SaveJpeg(outstream, width, height, 0, 85);
                    return outstream.ToArray();
                }
            }
        }
    }

Also I just noticed that the sample pictures on the phone are not having this problem, just the ones I've taken.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹梦 2024-11-12 06:52:57

我认为 WP7 不会读取方向的 EXIF 数据(很高兴得到纠正,因为我只是在 CTP SDK 推出时才尝试过)。但是,您可以使用 这个方法。另一种方法(我没有尝试过)可能是获取图像的旋转变换并将其旋转 90 度。变换旋转可能比手动移动可写位图的所有像素更快。

I don't think the EXIF data for orientation is read by WP7 (happy to be corrected as I've only tried when the CTP SDK was out). However, you can manually rotate your picture using this method. An alternative, which I haven't tried, could be to get the image's rotate transform and rotate it 90 degrees. Transform rotations may work out to be quicker than manually shifting all the pixels of the writeable bitmap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文