예제 #1
0
        /// <summary>
        /// Download image to disk.
        /// </summary>
        /// <param name="dirRef">A reference to objects created by the event</param>
        private void DownloadImage(IntPtr dirRef)
        {
            IntPtr stream = IntPtr.Zero;
            IntPtr data   = IntPtr.Zero;
            EdsDirectoryItemInfo dirItemInfo;

            try
            {
                UInt32 returnValue = EDSDK.EdsGetDirectoryItemInfo(dirRef, out dirItemInfo);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                string fullpath = String.Empty;
                if (!String.IsNullOrEmpty(ImageSaveDirectory))
                {
                    fullpath = System.IO.Path.Combine(ImageSaveDirectory, dirItemInfo.szFileName);
                }
                else
                {
                    fullpath = System.IO.Path.Combine(Environment.CurrentDirectory, dirItemInfo.szFileName);
                }
                returnValue = EDSDK.EdsCreateFileStream(fullpath, EdsFileCreateDisposition.CreateAlways, EdsAccess.ReadWrite, out stream);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                returnValue = EDSDK.EdsDownload(dirRef, dirItemInfo.Size, stream);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                if (returnValue == (uint )ReturnValue.Ok)
                {
                    returnValue = EDSDK.EdsDownloadComplete(dirRef);
                }
                else
                {
                    returnValue = EDSDK.EdsDownloadCancel(dirRef);
                }

                returnValue = EDSDK.EdsGetPointer(stream, out data);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
            }
            finally
            {
                EDSDK.EdsRelease(stream);
                EDSDK.EdsRelease(data);
            }
        }
예제 #2
0
        private ImageFile GetImageFile(IntPtr inRef, Folder aFolder)
        {
            EDSDK.EdsDirectoryItemInfo directoryItemInfo = GetDirectoryItemInfo(inRef);
            string filename = aFolder.ComposeFilename(directoryItemInfo.szFileName);
            IntPtr stream   = GetFileStream(filename);

            try
            {
                SDKHelper.CheckError(EDSDK.EdsDownload(inRef, directoryItemInfo.Size, stream));
                SDKHelper.CheckError(EDSDK.EdsDownloadComplete(inRef));
            }
            catch
            {
                SDKHelper.CheckError(EDSDK.EdsDownloadCancel(inRef));
                throw;
            }
            finally
            {
                SDKHelper.CheckError(EDSDK.EdsRelease(stream));
            }
            return(new ImageFile(File.ReadAllBytes(filename), directoryItemInfo.szFileName));
        }