我正在尝试使用C#,
将图像从Canon EOS M6复制到我的PC上我正在使用PTP / IP,到目前为止我能够与相机连接,查看SD卡并获取图像名称,但是当我尝试下载它们时,我收到了损坏的文件。
我认为它可能需要解码,所以我尝试使用Base64进行解码,但我无法使其正常工作。
static void readImageStream()
{
int bytesReceived = 0;
byte[] receivedData;
int count = 0;
receivedData = new byte[100];
var data = "";
try
{
//ns.Read(receivedData, 0, 32);
//Int64 numberOfBytes = BitConverter.ToInt64(receivedData, 0);
receivedData = new byte[34688];
//ns.Read(receivedData, 0, 24);
using (var fileIO = File.Create("d:\\Img_Test.jpg"))
{
do
{
count = ns.Read(receivedData, 0, receivedData.Length);
byte[] imageBytes = Convert.FromBase64String(GetByteString(receivedData));
Image img = null;
fileIO.Write(imageBytes, 0, imageBytes.Length);
bytesReceived += count;
}
while (ns.CanRead);
}
}
catch (Exception ex)
{
throw;
}
}
此处 ns 是 NetworkStream ns
请帮助我,
谢谢。