C# 佳能EDSDK是否在pc上下载或保存图像?

C# 佳能EDSDK是否在pc上下载或保存图像?,c#,canon-sdk,C#,Canon Sdk,我想用佳能c#SDK在我的电脑上保存图像? 如何在pc上下载拍摄的照片并在c#picturebox上显示?这是一个应用程序的摘录。它将图像下载到内存中,并返回带有图像的位图实例 public Bitmap DownloadImage(IntPtr ObjectPointer) { //get information about image EDSDK.EdsDirectoryItemInfo dirInfo = new EDSDK.EdsDirectoryItemInfo();

我想用佳能c#SDK在我的电脑上保存图像?
如何在pc上下载拍摄的照片并在c#picturebox上显示?

这是一个应用程序的摘录。它将图像下载到内存中,并返回带有图像的位图实例

public Bitmap DownloadImage(IntPtr ObjectPointer)
{
    //get information about image
    EDSDK.EdsDirectoryItemInfo dirInfo = new EDSDK.EdsDirectoryItemInfo();
    this.Parent.Lock(this.Ref);
    lock (LVlock) { Error = EDSDK.EdsGetDirectoryItemInfo(ObjectPointer, out dirInfo); }
    this.Parent.Unlock(this.Ref);
    //check the extension. Raw data cannot be read by the bitmap class
    string ext = Path.GetExtension(dirInfo.szFileName).ToLower();

    if (ext == ".jpg" || ext == ".jpeg")
    {
        Bitmap bmp = null;
        this.Parent.Lock(this.Ref);
        lock (LVlock)
        {
            IntPtr streamRef, jpgPointer;
            uint length;

            //create memory stream
            Error = EDSDK.EdsCreateMemoryStream(dirInfo.Size, out streamRef);
            //download data to the stream
            DownloadData(ObjectPointer, streamRef);
            Error = EDSDK.EdsGetPointer(streamRef, out jpgPointer);
            Error = EDSDK.EdsGetLength(streamRef, out length);

            unsafe
            {
                //create a System.IO.Stream from the pointer
                using (UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)jpgPointer.ToPointer(), length, length, FileAccess.Read))
                {
                    //create bitmap from stream (it's a normal jpeg image)
                    bmp = new Bitmap(ums);
                    //Tentar colocar um dispose no ums aqui
                }
            }

            //release data
            Error = EDSDK.EdsRelease(streamRef);
            //Error = EDSDK.EdsRelease(jpgPointer);


        }
        this.Parent.Unlock(this.Ref);
        return bmp;
    }
    else
    {
        //if it's a RAW image, cancel the download and release the image
        this.Parent.Lock(this.Ref);
        lock (LVlock)
        {
            Error = EDSDK.EdsDownloadCancel(ObjectPointer);
            Error = EDSDK.EdsRelease(ObjectPointer);
        }
        this.Parent.Unlock(this.Ref);
        return null;
    }
}
private void DownloadData(IntPtr ObjectPointer, IntPtr stream)
{

    //get information about the object
    EDSDK.EdsDirectoryItemInfo dirInfo;
    Error = EDSDK.EdsGetDirectoryItemInfo(ObjectPointer, out dirInfo);

    try
    {
        //set progress event
        Error = EDSDK.EdsSetProgressCallback(stream, SDKProgressCallbackEvent, EDSDK.EdsProgressOption.Periodically, ObjectPointer);
        //download the data
        Error = EDSDK.EdsDownload(ObjectPointer, dirInfo.Size, stream);
    }
    finally
    {
        //set the download as complete
        Error = EDSDK.EdsDownloadComplete(ObjectPointer);
        //release object
        Error = EDSDK.EdsRelease(ObjectPointer);
    }

}
我建议看一下这篇代码项目文章

欢迎来到堆栈溢出。你能把你到目前为止试过的东西贴出来吗?