c# 中的 Stream CopyTo() 方法无法正常工作
Stream CopyTo() method in c# not working as I want it to
我做错了什么?。下面是我的代码片段:
PhotoResult e;
using (var filebytes = new MemoryStream())
{
e.ChosenPhoto.CopyTo(filebytes);
Debug.WriteLine(e.ChosenPhoto.Length); // Outputs the correct length
Debug.WriteLine(filebytes.Length); //Outputs 0
}
很可能,您需要在执行复制之前重置 e.ChosenPhoto
的位置:
e.ChosenPhoto.Position = 0;
Copying begins at the current position in the current stream
我做错了什么?。下面是我的代码片段:
PhotoResult e;
using (var filebytes = new MemoryStream())
{
e.ChosenPhoto.CopyTo(filebytes);
Debug.WriteLine(e.ChosenPhoto.Length); // Outputs the correct length
Debug.WriteLine(filebytes.Length); //Outputs 0
}
很可能,您需要在执行复制之前重置 e.ChosenPhoto
的位置:
e.ChosenPhoto.Position = 0;
Copying begins at the current position in the current stream