public void DownloadLiveViewImage(Action <MemoryStream, uint> onImageRecieved) { IntPtr stream = IntPtr.Zero; IntPtr image = IntPtr.Zero; IntPtr pointer = IntPtr.Zero; uint size = 0; try { SDKHelper.CheckError(EDSDK.EdsCreateMemoryStream(BUFFER_SIZE, out stream)); SDKHelper.CheckError(EDSDK.EdsCreateEvfImageRef(stream, out image)); SDKHelper.CheckError(EDSDK.EdsDownloadEvfImage(_pointer, image)); SDKHelper.CheckError(EDSDK.EdsGetPointer(stream, out pointer)); SDKHelper.CheckError(EDSDK.EdsGetLength(stream, out size)); onImageRecieved(CopyToMemoryStream(pointer, size), size); SDKHelper.CheckError(EDSDK.EdsRelease(image)); SDKHelper.CheckError(EDSDK.EdsRelease(stream)); } catch (SDKComeBackLaterException) { } }
public unsafe static Bitmap DownloadEvf(IntPtr Camera) { uint success; Bitmap _bmp, _newbmp; UnmanagedMemoryStream ums; // while (true) { IntPtr _stream = IntPtr.Zero; IntPtr _image = new IntPtr(); IntPtr _imageData = new IntPtr(); uint _imageLen; int _width = 500, _height = 330; _newbmp = new Bitmap(_width, _height); success = EDSDK.EdsCreateMemoryStream(0, out _stream); if (success == EDSDK.EDS_ERR_OK) { success = EDSDK.EdsCreateEvfImageRef(_stream, out _image); } if (success == EDSDK.EDS_ERR_OK) { success = EDSDK.EdsDownloadEvfImage(Camera, _image); } if (success == EDSDK.EDS_ERR_OK) { EDSDK.EdsGetPointer(_stream, out _imageData); EDSDK.EdsGetLength(_stream, out _imageLen); ums = new UnmanagedMemoryStream((byte *)_imageData.ToPointer(), _imageLen, _imageLen, FileAccess.Read); _bmp = new Bitmap(ums, true); _newbmp = new Bitmap(_bmp, _width, _height); //LiveViewBox是定义的一个pictureBox 控件 //LiveViewBox1.Image = _newbmp; } if (_stream != IntPtr.Zero) { EDSDK.EdsRelease(_stream); _stream = IntPtr.Zero; } if (_image != IntPtr.Zero) { EDSDK.EdsRelease(_image); _image = IntPtr.Zero; } } return(_newbmp); }
public unsafe static Bitmap DownloadPreview(IntPtr Camera) { uint success; Bitmap _bmp, _newbmp; UnmanagedMemoryStream ums; //while (true) { IntPtr _stream = IntPtr.Zero; IntPtr _image = new IntPtr(); IntPtr _imageData = new IntPtr(); uint _imageLen; int _width = 1050, _height = 700; _newbmp = new Bitmap(_width, _height); success = EDSDK.EdsCreateMemoryStream(0, out _stream); if (success == EDSDK.EDS_ERR_OK) { success = EDSDK.EdsCreateEvfImageRef(_stream, out _image); } if (success == EDSDK.EDS_ERR_OK) { success = EDSDK.EdsDownloadEvfImage(Camera, _image); } if (success == EDSDK.EDS_ERR_OK) { EDSDK.EdsGetPointer(_stream, out _imageData); EDSDK.EdsGetLength(_stream, out _imageLen); ums = new UnmanagedMemoryStream((byte *)_imageData.ToPointer(), _imageLen, _imageLen, FileAccess.Read); _bmp = new Bitmap(ums, true); _newbmp = new Bitmap(_bmp, _width, _height); Console.WriteLine("bmp is download"); } if (_stream != IntPtr.Zero) { EDSDK.EdsRelease(_stream); _stream = IntPtr.Zero; Console.WriteLine("relase stream"); } if (_image != IntPtr.Zero) { EDSDK.EdsRelease(_image); _image = IntPtr.Zero; Console.WriteLine("relase image"); } } return(_newbmp); }
public Stream GetLiveViewImage() { IntPtr streamPointer = IntPtr.Zero; IntPtr imagePointer = IntPtr.Zero; UInt32 returnValue = EDSDK.EdsCreateMemoryStream(0, out streamPointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { returnValue = EDSDK.EdsCreateEvfImageRef(streamPointer, out imagePointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { returnValue = EDSDK.EdsDownloadEvfImage(this.Handle, imagePointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); IntPtr imageBlob; returnValue = EDSDK.EdsGetPointer(streamPointer, out imageBlob); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { ulong imageBlobLength; returnValue = EDSDK.EdsGetLength(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 { EDSDK.EdsRelease(imageBlob); } } finally { EDSDK.EdsRelease(imagePointer); } } finally { EDSDK.EdsRelease(streamPointer); } }
public void updatePic() { EDSDK.EdsDownloadEvfImage(this.CameraPtr, this.EvfImgPtr); IntPtr ptr; EDSDK.EdsGetPointer(MemStreamPtr, out ptr); uint len; EDSDK.EdsGetLength(MemStreamPtr, out len); Byte[] data = new Byte[len]; Marshal.Copy(ptr, data, 0, (int)len); System.IO.MemoryStream memStream = new System.IO.MemoryStream(data); bmp.BeginInit(); bmp.StreamSource = memStream; bmp.EndInit(); memStream.Dispose(); EDSDK.EdsRelease(ptr); }