1

I am trying to Copy an Image form Canon EOS M6 to my PC over wifi using C#,

I am using PTP/IP in this, so far I am able to get connected with camera, look into the SD card and get the Image Names but when I try to download them I am getting corrupted files.

I think it might need decoding, so I tried to decode using Base64 but I wasn't able to get it working.

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;
    }

}

here ns is NetworkStream ns

Please help me with this,

Thank you.

Anastasios Selmani
  • 3,579
  • 3
  • 32
  • 48
  • Converting from incomplete Base64 will give corrupt data since the end of a character in the stream is never guaranteed to be the end of a full byte. If the file is indeed in Base64, then you will need to keep a buffer in memory, and only convert it after you have all the data. – Nyerguds Jan 04 '18 at 10:05
  • Overall, I advise simply saving a full transferred file raw as it is sent, and just using a hex editor to check what that looks like. Since this is a conversion problem, it's hard to see without the actual data. – Nyerguds Jan 04 '18 at 10:08

0 Answers0