0

在 Windows Phone 8 C# 中实例化 ExifReader 时出现错误。请在下面找到代码片段。请做需要的事

错误:“ExifLib 需要可搜索的流”

byte[] imageBytes = (byte[])PhoneApplicationService.Current.State["ViewImage"];

MemoryStream ms = new MemoryStream(imageBytes,0,imageBytes.Length);

BitmapImage bitmapImage = new BitmapImage();

bitmapImage.SetSource(ms);

try
{
    ExifReader xif = new ExifReader(toStream(bitmapImage)); // Getting Error here
    double gpsLat, gpsLng;
    xif.GetTagValue<double>(ExifTags.GPSLatitude, out gpsLat);
    xif.GetTagValue<double>(ExifTags.GPSLongitude, out gpsLng);

    map.Center = new System.Device.Location.GeoCoordinate(gpsLat, gpsLng);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message.ToString());
}

Stream toStream(BitmapImage img)
{
    WriteableBitmap bmp = new WriteableBitmap((BitmapSource)img);
    using (MemoryStream stream = new MemoryStream())
    {
        bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
        stream.Position = 0;
        return stream;
    }
}
4

1 回答 1

0

你在被调用MemoryStream时返回 false 。CanSeek这是因为您已将您的声明包装MemoryStream在一个using语句中,这意味着您正在返回一个已处置的对象。

您的toStream方法实际上应该如下所示:

Stream ToStream(BitmapImage img)
{
    MemoryStream stream = new MemoryStream();
    using (WriteableBitmap bmp = new WriteableBitmap((BitmapSource)img))
    {
        bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
    }
    stream.Position = 0;
    return stream;
}
于 2014-03-24T23:36:22.010 回答