0

我正在尝试使用 C# 通过 wifi 将图像从 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;
    }

}

这里nsNetworkStream ns

请在这件事上给予我帮助,

谢谢你。

4

0 回答 0