开发者

Writeablebitmap.SaveJpeg is rotating my image -90 degrees

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 par开发者_如何学Cameter 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜