我想克隆IRandomAccessStream。我尝试了CloneStream()来克隆流,但是不支持它。有什么方法可以克隆随机访问流。
谢谢, Santhiya A
答案 0 :(得分:2)
您可以使用CopyTo方法
https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.copyto?view=netframework-4.7.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;
}