dami akawnt
dami akawnt

Reputation: 9

Save photo to PC | Canon ESDK

I am trying to build an application with Canon EDSDK using C#. The shutter trigger works fine and it is taking photos, but they are not being saved to my computer

Here's my code for downloading image directly to computer

private void DownloadImage(IntPtr directoryItem, string downloadPath)
{
    uint err = EdsGetDirectoryItemInfo(directoryItem, out EdsDirectoryItemInfo dirItemInfo);
    if (err != 0)
    {
        _logger.LogError("Failed to get directory item info with status code: {0}", err);
        return;
    }

    string fullPath = Path.Combine(downloadPath, dirItemInfo.szFileName);
    _logger.LogInformation("Downloading image to: {0}", fullPath);

    try
    {
        if (!Directory.Exists(downloadPath))
        {
            _logger.LogInformation("Directory does not exist. Creating directory: {0}", downloadPath);
            Directory.CreateDirectory(downloadPath);
        }

        IntPtr stream;
        err = EdsCreateFileStream(fullPath, 2 /* kEdsFile_CreateAlways */, 3 /* kEdsAccess_ReadWrite */, out stream);
        if (err != 0)
        {
            _logger.LogError("Failed to create file stream with status code: {0}", err);
            return;
        }

        err = EdsDownload(directoryItem, dirItemInfo.size, stream);
        if (err != 0)
        {
            _logger.LogError("Failed to download image with status code: {0}", err);
            EdsRelease(stream);
            return;
        }

        err = EdsDownloadComplete(directoryItem);
        if (err != 0)
        {
            _logger.LogError("Failed to complete download with status code: {0}", err);
        }
        EdsRelease(stream);

Upvotes: 0

Views: 72

Answers (0)

Related Questions