我正在使用以下代码从手机上的 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();
}
}
}
}
另外我刚刚注意到手机上的样张没有这个问题,只是我拍的那些。
最佳答案
我认为方向的 EXIF 数据不会被 WP7 读取(很高兴得到更正,因为我只在 CTP SDK 推出时尝试过)。但是,您可以使用 this method 手动旋转图片.我还没有尝试过的另一种方法是获取图像的旋转变换并将其旋转 90 度。变换旋转可能比手动移动可写位图的所有像素更快。
关于c# - Writeablebitmap.SaveJpeg 正在旋转我的图像 -90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5917102/