2016-10-14 50 views
0

我想从StreamImageSource获取流。 我用手机相机拍了一张照片,并在表格上显示一点预览。因此我将图片流加载到ImageSource中。从Imagesource获取流

现在我要回去了......流但我的方法,我总是得到一个异常“无法访问已关闭的流”

private static async Task<Stream> GetStreamFromImageSourceAsync(StreamImageSource imageSource, CancellationToken cancellationToken = default(CancellationToken)) 
    { 
     if (imageSource.Stream != null) 
     { 
      return await imageSource.Stream(cancellationToken); 
     } 
     return null; 
    } 

这是调用例程

var s = await GetStreamFromImageSourceAsync((StreamImageSource)item.Source);       
s.Position = 0; 

在这里我得到的例外,我无法从封闭的流中读取

谢谢你们...

+0

你不能。您需要从相机取出原始图像并保存,以便稍后参考。 – Jason

回答

0

一旦消耗了Stream以显示预览,它将被关闭,您不能再使用它了。

你可以做的是,一旦你从相机获取流,将其复制到MemoryStream中,并且该MemoryStream可以随意使用和重用。