private uint DownloadImage(uint inEvent, IntPtr inRef, IntPtr inContext) { _cameraNotifications.Log(string.Format("Camera event: {0}", SDKHelper.DecodeEvent(inEvent))); lock (_synchronizationObject) { try { if (inEvent == EDSDK.ObjectEvent_DirItemRequestTransfer) { if (_imageHandler != null) { _imageHandler.Handle(GetImageFile(inRef, _folder)); } _cameraNotifications.CameraDone(); } if (inEvent == EDSDK.ObjectEvent_DirItemCreated) { _cameraNotifications.CameraDone(); } } finally { if (inRef != IntPtr.Zero) { SDKHelper.CheckError(EDSDK.EdsRelease(inRef)); } } return(0); } }
public IEnumerable <Camera> GetCameras() { UInt32 returnValue; IntPtr cameraListPointer; returnValue = EDSDK.EdsGetCameraList(out cameraListPointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); try { Int32 cameraListCount; returnValue = EDSDK.EdsGetChildCount(cameraListPointer, out cameraListCount); ReturnValueManager.HandleFunctionReturnValue(returnValue); for (var i = 0; i < cameraListCount; ++i) { IntPtr cameraPointer; returnValue = EDSDK.EdsGetChildAtIndex(cameraListPointer, i, out cameraPointer); ReturnValueManager.HandleFunctionReturnValue(returnValue); Camera camera = new Camera(cameraPointer); yield return(camera); } } finally { // Release Camera List Pointer if (cameraListPointer != IntPtr.Zero) { EDSDK.EdsRelease(cameraListPointer); } } }
public void stopLV() { this.LvActive = false; Thread.Sleep(500); EDSDK.EdsRelease(this.MemStreamPtr); EDSDK.EdsRelease(this.EvfImgPtr); }
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 byte[] DownloadLastPhoto() { int count; uint err; IntPtr?dirInfo = getDCIMFolder(); IntPtr folderHandle; IntPtr imageHandle; EDSDK.EdsDirectoryItemInfo imageInfo; IntPtr memStream; IntPtr streamStart; //MAKE SURE WE HAVE A DCIM FOLDER if (dirInfo == null) { if (errorEvent != null) { errorEvent("Failed To Find DCIM Folder"); } return(null); } err = EDSDK.EdsGetChildCount(dirInfo.Value, out count); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed To Get Child Folder!"); } return(null); } err = EDSDK.EdsGetChildAtIndex(dirInfo.Value, count - 1, out folderHandle); err = EDSDK.EdsGetChildCount(folderHandle, out count); err = EDSDK.EdsGetChildAtIndex(folderHandle, count - 1, out imageHandle); err = EDSDK.EdsGetDirectoryItemInfo(imageHandle, out imageInfo); err = EDSDK.EdsCreateMemoryStream(0, out memStream); EDSDK.EdsDownload(imageHandle, imageInfo.Size, memStream); EDSDK.EdsDownloadComplete(imageHandle); byte[] imageData = new byte[imageInfo.Size]; EDSDK.EdsGetPointer(memStream, out streamStart); Marshal.Copy(streamStart, imageData, 0, (int)imageInfo.Size); EDSDK.EdsRelease(streamStart); EDSDK.EdsRelease(memStream); EDSDK.EdsRelease(folderHandle); EDSDK.EdsRelease(imageHandle); EDSDK.EdsRelease(dirInfo.Value); DownloadingPhoto = false; return(imageData); }
public void Dispose() { uint err = 0; //CLOSE THE CAMERA SESSION (ASSUMING THERE IS ONE) RELEASE THE CAMERA AND TERMINATE THE SDK err = EDSDK.EdsCloseSession(camObj); err = EDSDK.EdsRelease(camObj); err = EDSDK.EdsTerminateSDK(); }
public virtual void Dispose() { if (this.Handle != IntPtr.Zero) { UInt32 returnValue = EDSDK.EdsRelease(this.Handle); this.Handle = IntPtr.Zero; } }
public void Dispose() { _folder.Dispose(); if (_shouldRelease) { SDKHelper.CheckError(EDSDK.EdsCloseSession(_pointer)); SDKHelper.CheckError(EDSDK.EdsRelease(_pointer)); } _disposed = true; }
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); } }
/// <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); } }
private uint propEventHandler(uint inEvent, uint inPropertyID, uint inParam, IntPtr inContext) { switch (inEvent) { case EDSDK.PropertyEvent_PropertyChanged: switch (inPropertyID) { case EDSDK.PropID_AEMode: if (CameraModeChanged != null) { CameraModeChanged((CameraModes)CurrentCameraMode); } break; case EDSDK.PropID_ISOSpeed: if (ISOSpeedChanged != null) { ISOSpeedChanged((ISOSpeeds)CurrentISOSpeed); } break; case EDSDK.PropID_ExposureCompensation: if (ExposureCompensationChanged != null) { ExposureCompensationChanged((ExposureCompensations)CurrentExposureCompensation); } break; case EDSDK.PropID_BatteryLevel: if (BatteryLevelChanged != null) { BatteryLevelChanged(CurrentBatteryLevel); } break; } break; case EDSDK.PropertyEvent_PropertyDescChanged: break; } if (inContext != IntPtr.Zero) { EDSDK.EdsRelease(inContext); } return(0); }
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); }
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)); }
private uint stateEventHandler(uint inEvent, uint inParameter, IntPtr inContext) { switch (inEvent) { case EDSDK.StateEvent_AfResult: break; case EDSDK.StateEvent_BulbExposureTime: break; case EDSDK.StateEvent_CaptureError: break; case EDSDK.StateEvent_InternalError: break; case EDSDK.StateEvent_JobStatusChanged: break; case EDSDK.StateEvent_Shutdown: break; case EDSDK.StateEvent_ShutDownTimerUpdate: break; case EDSDK.StateEvent_WillSoonShutDown: break; } if (inContext != IntPtr.Zero) { EDSDK.EdsRelease(inContext); } return(0); }
public static unsafe void DownloadImage(IntPtr[] camera, int Count) { IntPtr sdRef = IntPtr.Zero; IntPtr dicmRef = IntPtr.Zero; IntPtr canonRef = IntPtr.Zero; int nFiles; IniFile iniFile = new IniFile(configForm.iniFilePaths); for (int i = 0; i < Count; i++) { EDSDK.EdsGetChildAtIndex(camera[i], 0, out sdRef); EDSDK.EdsGetChildAtIndex(sdRef, 0, out dicmRef); EDSDK.EdsGetChildAtIndex(dicmRef, 0, out canonRef); EDSDK.EdsGetChildCount(canonRef, out nFiles); string dest = PicDest; //for (int i = 0; i < 5; i++) { IntPtr fileRef = IntPtr.Zero; EDSDK.EdsDirectoryItemInfo fileInfo; #region Get Directory and download try { EDSDK.EdsGetChildAtIndex(canonRef, (nFiles - 1), out fileRef); EDSDK.EdsGetDirectoryItemInfo(fileRef, out fileInfo); IntPtr fStream = IntPtr.Zero; //it's a cannon sdk file stream, not a managed stream uint fSize = fileInfo.Size; #region DownLoad try { EDSDK.EdsCreateMemoryStream(fSize, out fStream); EDSDK.EdsDownload(fileRef, fSize, fStream); EDSDK.EdsDownloadComplete(fileRef); byte[] buffer = new byte[fSize]; IntPtr imgLocation; //uint _imageLen; if (EDSDK.EdsGetPointer(fStream, out imgLocation) == EDSDK.EDS_ERR_OK) { #region save Marshal.Copy(imgLocation, buffer, 0, (int)fSize - 1); EDSDK.EdsDeviceInfo deviceInfo; EDSDK.EdsGetDeviceInfo(camera[i], out deviceInfo); string deviceName; deviceName = iniFile.IniReadValue("CameraID", deviceInfo.szPortName); File.WriteAllBytes(dest + deviceName + "__" + fileInfo.szFileName, buffer); //EDSDK.EdsGetLength(fStream, out _imageLen); //UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)imgLocation.ToPointer(), _imageLen, _imageLen, FileAccess.Read); //Bitmap _bmp = new Bitmap(ums, true); //pictureBox1.Image = _bmp; //_bmp.Save("new1", System.Drawing.Imaging.ImageFormat.Jpeg); #endregion } } finally { EDSDK.EdsRelease(fStream); Console.WriteLine("DownloadSuccess\t" + i.ToString()); } #endregion } finally { EDSDK.EdsRelease(fileRef); } #endregion } } }
private void savePictureToHost(IntPtr ptr, string path) { Canon_EOS_Remote.classes.Image tmpImage; tmpImage = new classes.Image(ptr); Byte[] byteArray = new byte[(int)tmpImage.ImageItemInfo.Size]; uint error = 0; IntPtr outputStream; error = EDSDK.EdsCreateMemoryStream((uint)tmpImage.ImageItemInfo.Size, out outputStream); if (error != 0) { Console.WriteLine("Error at creating file stream : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } error = EDSDK.EdsDownload(ptr, (uint)tmpImage.ImageItemInfo.Size, outputStream); if (error != 0) { Console.WriteLine("Error at download : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } IntPtr imageRef = IntPtr.Zero; error = EDSDK.EdsCreateImageRef(outputStream, out imageRef); if (error != 0) { Console.WriteLine("Error at createimageref : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } EDSDK.EdsImageInfo imageinfo; error = EDSDK.EdsGetImageInfo(imageRef, EDSDK.EdsImageSource.FullView, out imageinfo); if (error != 0) { Console.WriteLine("Error at getiamgeinfo : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } error = EDSDK.EdsRelease(imageRef); if (error != 0) { Console.WriteLine("Error at release imageref : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } GCHandle gcHandle = GCHandle.Alloc(byteArray, GCHandleType.Pinned); IntPtr adress = gcHandle.AddrOfPinnedObject(); IntPtr streamRef = IntPtr.Zero; error = EDSDK.EdsGetPointer(outputStream, out streamRef); if (error != 0) { Console.WriteLine("Error at getpointer : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } Marshal.Copy(streamRef, byteArray, 0, (int)tmpImage.ImageItemInfo.Size); try { FileStream fstream = new FileStream(path + tmpImage.ImageItemInfo.szFileName, FileMode.Create); fstream.Write(byteArray, 0, byteArray.Length); fstream.Close(); } catch (UnauthorizedAccessException e) { Console.WriteLine("Zugriff verweigert."); System.Windows.MessageBox.Show("Zugriff verweigert : \n" + e.Message); } catch (Exception e) { Console.WriteLine("Exception at filestream : " + e.Message); } finally { error = EDSDK.EdsRelease(outputStream); if (error != 0) { Console.WriteLine("Error at release outputstream : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } error = EDSDK.EdsRelease(streamRef); if (error != 0) { Console.WriteLine("Error at at release streamref : " + ErrorCodes.getErrorDataWithCodeNumber(error)); } gcHandle.Free(); } }
private uint objEventHandler(uint inEvent, IntPtr inRef, IntPtr inContext) { switch (inEvent) { case EDSDK.ObjectEvent_DirItemContentChanged: break; case EDSDK.ObjectEvent_DirItemCreated: TakingPhoto = false; Application.DoEvents(); System.Threading.Thread tmpThread = new Thread(delegate() { if (!DownloadingPhoto) { DownloadingPhoto = true; if (PictureSaved != null) { byte[] tmpPhoto = DownloadLastPhoto(); PictureSaved(tmpPhoto); } } }); tmpThread.Start(); break; case EDSDK.ObjectEvent_DirItemInfoChanged: break; case EDSDK.ObjectEvent_DirItemRemoved: break; case EDSDK.ObjectEvent_DirItemRequestTransfer: break; case EDSDK.ObjectEvent_DirItemRequestTransferDT: break; case EDSDK.ObjectEvent_FolderUpdateItems: break; case EDSDK.ObjectEvent_VolumeAdded: break; case EDSDK.ObjectEvent_VolumeInfoChanged: break; case EDSDK.ObjectEvent_VolumeRemoved: break; case EDSDK.ObjectEvent_VolumeUpdateItems: break; } if (inContext != IntPtr.Zero) { EDSDK.EdsRelease(inContext); } return(0); }
private IntPtr?getDCIMFolder() { uint err; int count = 0; IntPtr volume = getVolume(); IntPtr dirHandle; EDSDK.EdsDirectoryItemInfo dirInfo; //GET THE ROOT VOLUME FOR THE CAMERA if (volume == IntPtr.Zero) { if (errorEvent != null) { errorEvent("Failed To Get Root Volume!"); } return(null); } //GET THE COUNT OF FOLDERS ON THE VOLUME err = EDSDK.EdsGetChildCount(volume, out count); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed To Get Folders on Volume!"); } return(null); } for (int i = 0; i < count && err == EDSDK.EDS_ERR_OK; i++) { err = EDSDK.EdsGetChildAtIndex(volume, i, out dirHandle); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to get Folder at index " + i.ToString()); } return(null); } err = EDSDK.EdsGetDirectoryItemInfo(dirHandle, out dirInfo); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed To Get Folder At Index " + i.ToString()); } return(null); } if (dirInfo.szFileName.ToUpper().Contains("DCIM") && dirInfo.isFolder == 1) { EDSDK.EdsRelease(volume); return(dirHandle); } else { EDSDK.EdsRelease(dirHandle); } } return(null); }
private void UnInitialize() { Array.ForEach(_processors.Values.ToArray(), cameraProcessor => cameraProcessor.Dispose()); SDKHelper.CheckError(EDSDK.EdsRelease(_cameraListPointer)); SDKHelper.CheckError(EDSDK.EdsTerminateSDK()); }
private void btn_liveview_click(object sender, RoutedEventArgs e) { //IntPtr device = new IntPtr(0); //Int32 device = 0; //Int32 device ; //device |= EDSDK.EvfOutputDevice_PC; //object device; /* * if(camera == null) * { * label.Content = "camera is null"; * }else * { * label.Content = "camera is not null"; * } */ int size = Marshal.SizeOf(typeof(Size)); IntPtr device = Marshal.AllocHGlobal(size); //EdsError = EDSDK.EdsGetPropertySize(camera, EDSDK.PropID_Evf_OutputDevice, 0, out device, IntPtr.Size); EdsError = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, device); //EdsGetPropertyData(IntPtr inRef, uint inPropertyID, int inParam, out uint outPropertyData) //EDSDK.EvfOutputDevice_PC if (EdsError == EDSDK.EDS_ERR_OK) { label.Content = "OK"; IntPtr stream; IntPtr outImg = new IntPtr(0);; EdsError = EDSDK.EdsCreateMemoryStream(0, out stream); if (EdsError == EDSDK.EDS_ERR_OK) { EdsError = EDSDK.EdsCreateEvfImageRef(stream, out outImg); } if (EdsError == EDSDK.EDS_ERR_OK) { EdsError = EDSDK.EdsDownloadEvfImage(camera, outImg); } //image.set if (stream != null) { EDSDK.EdsRelease(stream); } if (outImg != null) { EDSDK.EdsRelease(outImg); } //EdsError = EDSDK.EdsCreateEvfImageRef( } else if (EdsError == EDSDK.EDS_ERR_INVALID_POINTER) { label.Content = EdsError; } }