public Stream GetLiveViewImage() { IntPtr streamPointer = IntPtr.Zero; IntPtr imagePointer = IntPtr.Zero; UInt32 returnValue = EDSDKInvokes.CreateMemoryStream(0, out streamPointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { returnValue = EDSDKInvokes.CreateEvfImageRef(streamPointer, out imagePointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { returnValue = EDSDKInvokes.DownloadEvfImage(this.Handle, imagePointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); IntPtr imageBlob; returnValue = EDSDKInvokes.GetPointer(streamPointer, out imageBlob); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { uint imageBlobLength; returnValue = EDSDKInvokes.GetLength(streamPointer, out imageBlobLength); ReturnValueManager.HandleFunctionReturnValue(returnValue); byte[] buffer = new byte[imageBlobLength]; Marshal.Copy(imageBlob, buffer, 0, (int)imageBlobLength); Stream stream = new MemoryStream(buffer); return(stream); } finally { EDSDKInvokes.Release(imageBlob); } } finally { EDSDKInvokes.Release(imagePointer); } } finally { EDSDKInvokes.Release(streamPointer); } }
/// <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; DirectoryItemInformation dirItemInfo; try { UInt32 returnValue = EDSDKInvokes.GetDirectoryItemInformation(dirRef, out dirItemInfo); ReturnValueManager.HandleFunctionReturnValue(returnValue); string fullpath = String.Empty; if (!String.IsNullOrEmpty(ImageSaveDirectory)) { fullpath = System.IO.Path.Combine(ImageSaveDirectory, dirItemInfo.FileName); } else { fullpath = System.IO.Path.Combine(Environment.CurrentDirectory, dirItemInfo.FileName); } returnValue = EDSDKInvokes.CreateFileStream(fullpath, FileCreateDisposition.CreateAlways, Access.ReadWrite, out stream); ReturnValueManager.HandleFunctionReturnValue(returnValue); returnValue = EDSDKInvokes.Download(dirRef, dirItemInfo.Size, stream); ReturnValueManager.HandleFunctionReturnValue(returnValue); if (returnValue == (uint )ReturnValue.Ok) { returnValue = EDSDKInvokes.DownloadComplete(dirRef); } else { returnValue = EDSDKInvokes.DownloadCancel(dirRef); } returnValue = EDSDKInvokes.GetPointer(stream, out data); ReturnValueManager.HandleFunctionReturnValue(returnValue); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } finally { EDSDKInvokes.Release(stream); EDSDKInvokes.Release(data); } }