如何克隆随机访问流?

时间:2018-12-17 10:00:20

标签: xamarin.forms uwp stream cross-platform xamarin.uwp

我想克隆IRandomAccessStream。我尝试了CloneStream()来克隆流,但是不支持它。有什么方法可以克隆随机访问流。

谢谢, Santhiya A

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

您可以尝试将其转换为byte[],然后将byte[]克隆到新的IRandomAccessStream中。

    public async Task<IRandomAccessStream> CloneIRandomeAccessStream(IRandomAccessStream randomAccessStream)
    {
        var reader = new DataReader(randomAccessStream.GetInputStreamAt(0));
        byte[] bytes = new byte[randomAccessStream.Size];
        await reader.LoadAsync((uint)randomAccessStream.Size);
        reader.ReadBytes(bytes);
        MemoryStream stream = new MemoryStream(bytes.ToArray());
        IRandomAccessStream ClonerandomAccessStream = stream.AsRandomAccessStream();
        return ClonerandomAccessStream;
    }