コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: thrixton/edsdk-wrapper
        /// <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);
            }
        }
コード例 #3
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
                }
            }
        }
コード例 #4
0
 public Folder(IntPtr ptr)
 {
     this.Ptr = ptr;
     EDSDK.EdsGetDirectoryItemInfo(this.Ptr, out _folderInfo);
 }
コード例 #5
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);
        }
コード例 #6
0
 private static EDSDK.EdsDirectoryItemInfo GetDirectoryItemInfo(IntPtr inRef)
 {
     EDSDK.EdsDirectoryItemInfo directoryItemInfo;
     SDKHelper.CheckError(EDSDK.EdsGetDirectoryItemInfo(inRef, out directoryItemInfo));
     return(directoryItemInfo);
 }
コード例 #7
0
 public Image(IntPtr ptr)
 {
     this.Ptr = ptr;
     EDSDK.EdsGetDirectoryItemInfo(this.Ptr, out _imageItemInfo);
 }