Search code examples
c#edsdkcanon-sdk

What is the fastest download method for images using Canons EDSDK?


I created a Camera Controller application for Canon Cameras using the C# EDSDK. I am able to download images to the host PC, but it still takes a lot of time in comparison to Canons EOS Utility Software. Currently I'm downloading a 22 Megapixel Jpg image in about 2.5 seconds. When I use Canons software it takes less than a second. For a RAW image (22MPixel) it takes about 2 to 3 seconds with the Canons Utility Software and about 11 seconds using the SDK.

I'm using the following code in my EventHandler:

public void DownloadImage(DownloadItem item)
{
        EDSDK.EdsDirectoryItemInfo dirInfo;
        IntPtr streamRef;
        Stopwatch timer = new Stopwatch();
        timer.Start();
        Error = EDSDK.EdsGetDirectoryItemInfo(item.ImageObjectPointer, 
                                              out dirInfo);
        Error = EDSDK.EdsCreateFileStream(
                                item.FilePath, 
                                EDSDK.EdsFileCreateDisposition.CreateAlways, 
                                EDSDK.EdsAccess.ReadWrite, 
                                out streamRef);

        Error = EDSDK.EdsDownload(item.ImageObjectPointer, dirInfo.Size, streamRef);
        //Tell the SDK we finished the download
        Error = EDSDK.EdsDownloadComplete(item.ImageObjectPointer);
        //Release Resources
        Error = Release(streamRef);
        Error = Release(item.ImageObjectPointer);
        timer.Stop();
        var ms = timer.ElapsedMilliseconds;
        this.Log().DebugFormat("Download time for image {0}: \t{1}\t ms",
                                Path.GetFileName(item.FilePath),
                                ms.ToString());

    }

Does anyone know about a faster download routine for images? Or does Canon use completely different routines in their software?

Thanks in advance for your help!


Solution

  • Solved the mystery! The code above is the fastest download method for images as far as I know. I also tried to download the image into a memory stream and then save the image, like JohannesB suggested (see comments above). As he already mentioned, it doesn't make a big difference in terms of download times, but in the end it helped me to find out that most time was spent for saving the image.

    The reason for the long save times was the selected file location. By default it pointed to Environment.SpecialFolder.MyPictures. This was pointing to my network drive. When I selected my local drive, the save times went down to 150ms for a 22MPixel Jpeg.

    Thanks a lot for your help!