Example #1
0
        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)
            {
            }
        }
Example #2
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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
            }
        }
Example #6
0
        public bool startLV()
        {
            uint err    = 0;
            uint device = 0;

            EvfImgPtr    = new IntPtr(0);
            MemStreamPtr = new IntPtr(0);
            Bmp          = new BitmapImage();
            err          = EDSDK.EdsGetPropertyData(this.CameraPtr, EDSDK.PropID_Evf_OutputDevice, 0, out device);
            Console.WriteLine("Cant get output device because : " + err);
            Thread.Sleep(1000);
            err = EDSDK.EdsSetPropertyData(this.CameraPtr, EDSDK.PropID_Evf_OutputDevice, 0, Marshal.SizeOf(EDSDK.EvfOutputDevice_PC), EDSDK.EvfOutputDevice_PC);
            Console.WriteLine("Cant set output device because : " + err);
            err = EDSDK.EdsCreateMemoryStream(0, out memStreamPtr);
            Console.WriteLine("Cant create memory stream because : " + err);
            err = EDSDK.EdsCreateEvfImageRef(memStreamPtr, out evfImgPtr);
            Console.WriteLine("Cant create evfimagestream because : " + err);
            Thread.Sleep(2000);
            return(true);
        }
Example #7
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
                }
            }
        }
Example #8
0
        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();
            }
        }
Example #9
0
        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;
            }
        }