private static IntPtr GetFileStream(string filename) { IntPtr stream; SDKHelper.CheckError(EDSDK.EdsCreateFileStream(filename, EDSDK.EdsFileCreateDisposition.CreateAlways, EDSDK.EdsAccess.ReadWrite, out stream)); return(stream); }
/// <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); } }