简体   繁体   English

从图像源获取流

[英]Get Stream from Imagesource

I want to get a Stream from a StreamImageSource.我想从 StreamImageSource 获取 Stream。 I took a pic with the phonecamera and show a little preview on the form.我用手机拍了一张照片,并在表格上显示了一些预览。 Therefore I load the picture stream in a ImageSource.因此我在 ImageSource 中加载图片流。

Now I want to get back the Stream ... but with my approach I always get an exception that "Cannot access a closed Stream"现在我想取回 Stream ......但是用我的方法我总是得到一个“无法访问关闭的流”的异常

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

This is the caller routine这是调用程序

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

and here i get the exception that i cannot read from a closed stream在这里我得到了无法从关闭的流中读取的异常

thank you guys ...谢谢你们 ...

Once the Stream is consumed to display the preview, it gets closed and you can't use it anymore.一旦使用 Stream 来显示预览,它就会关闭并且您不能再使用它。

What you can do is, once you get the Stream from the camera, copy it in a MemoryStream , and that MemoryStream can be used and reused at will.您可以做的是,一旦您从相机获取 Stream ,将其复制到MemoryStream ,并且该MemoryStream可以随意使用和重复使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM