Ejemplo n.º 1
0
        //Take picture using the same aspect ratio as the preview
        public void TakePicture(string file, FlashMode flashMode)
        {
            int width, height;

            if (mRotate)
            {
                width  = _TextureView.Height;
                height = _TextureView.Width;
            }
            else
            {
                width  = _TextureView.Width;
                height = _TextureView.Height;
            }

            var sizes = getSizesSupported(Format.Jpeg);
            var size  = getBestSize(sizes, width, height);

            var c        = mCameraManager.GetCameraCharacteristics(_id);
            int rotation = (int)c.Get(CameraCharacteristics.SensorOrientation);

            //if (_lensFacing == LensFacing.Front)
            //	rotation *= -1;

            rotation = getJpegOrientation(rotation, 0, _lensFacing);

            TakePicture(file, flashMode, size.Width, size.Height, rotation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the <paramref name="flashMode"/> on the current flash control.
        /// </summary>
        /// <param name="flashMode">Flash mode.</param>
        protected void SetFlashMode(FlashMode flashMode)
        {
            if (!this.CameraController.FlashSupported)
            {
                return;
            }

            switch (flashMode)
            {
            case FlashMode.Off:
                this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Enabled = false;
                this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Auto    = false;
                break;

            case FlashMode.On:
                this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Enabled = true;
                this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Auto    = false;
                break;

            case FlashMode.Auto:
                this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Enabled = true;
                this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Auto    = true;
                break;
            }
        }
Ejemplo n.º 3
0
        public string AsFlashMode()
        {
            FlashMode flashMode = (FlashMode)Value;

            switch (flashMode)
            {
            case FlashMode.AutoFlash: return("Autoflash");

            case FlashMode.FlashOff: return("Flash Off");

            case FlashMode.FillFlash: return("Fill-flash");

            case FlashMode.EyeFlashAuto: return("Eye-flash Auto");

            case FlashMode.EyeFlash: return("Eye-flash");

            case FlashMode.AltSlowSync: return("Slow Sync (alt?).");

            case FlashMode.SlowSync: return("Slow Sync.");

            case FlashMode.RearSync: return("Rear Sync.");

            case FlashMode.EyeFlashAuto_SlowSync: return("Eye-flash Autio (Slow Sync.)");

            case FlashMode.SlowWL: return("Slow WL");

            case FlashMode.RearWL: return("Rear WL");

            default: return("???(" + Value + ")");
            }
        }
Ejemplo n.º 4
0
        //Take a picture
        public void TakePicture(string file, FlashMode flashMode, int width, int height, int rotation)
        {
            ImageReader imageReader = ImageReader.NewInstance(width, height, ImageFormatType.Jpeg, 1);

            imageReader.SetOnImageAvailableListener(this, mHandler);

            //The surface for the image
            var imageSurface = imageReader.Surface;

            List <Surface> surfaces = new List <Surface>();

            surfaces.Add(imageSurface);

            //the surface for the preview
            if (_TextureView != null)
            {
                var previewSurface = getPreviewSurface();
                surfaces.Add(previewSurface);
            }

            var builder = mDevice.CreateCaptureRequest(CameraTemplate.StillCapture);

            builder.Set(CaptureRequest.JpegOrientation, rotation);

            mMediaFile = file;
            createCapture(surfaces, flashMode, false, builder);
        }
Ejemplo n.º 5
0
        private async void Instance_ChatMessageListChanged(object sender, ChatMessageListEventArgs e)
        {
            flashMode          = FlashMode.ChatMessage;
            channelName        = e.Channel;
            pagedSequentialKey = e.CurrentPage * (e.NumberOfKeys - 2) + sequentialKey;
            if (sequentialKey == 0)
            {
                await Connection.SetTitleAsync("Exit");
            }
            else if (e.ChatMessageKeys != null && sequentialKey == e.NumberOfKeys - 1 && e.ChatMessageKeys.Length > pagedSequentialKey) // There is more than one page)
            {
                await Connection.SetTitleAsync(">>");

                numberOfElements = e.ChatMessageKeys.Length;
                numberOfKeys     = e.NumberOfKeys;
            }
            else if (e.ChatMessageKeys != null && e.ChatMessageKeys.Length >= pagedSequentialKey) // >= because we're doing -1 as we're starting on the second key
            // +1 because starting on second key
            {
                var userInfo = e.ChatMessageKeys[pagedSequentialKey - 1];
                using (Image image = FetchImage(userInfo.KeyImageURL.Replace(PREVIEW_IMAGE_WIDTH_TOKEN, PREVIEW_IMAGE_WIDTH_PIXELS.ToString()).Replace(PREVIEW_IMAGE_HEIGHT_TOKEN, PREVIEW_IMAGE_HEIGHT_PIXELS.ToString())))
                {
                    await DrawChatMessageImage(userInfo, image);
                }
                chatMessage = userInfo.ChatMessage;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="paramode">Paramode.</param>
 public static void setFlashMode(FlashMode paramode)
 {
     if (easyWebCamInterface != null)
     {
         easyWebCamInterface.setFocusMode((int)paramode);
     }
 }
Ejemplo n.º 7
0
        private async void Instance_ActiveStreamersChanged(object sender, ActiveStreamersEventArgs e)
        {
            flashMode                    = FlashMode.ActiveStreamers;
            pagedSequentialKey           = e.CurrentPage * (e.NumberOfKeys - 2) + sequentialKey;
            channelName                  = String.Empty;
            liveStreamersLongPressAction = e.LongPressAction;
            if (sequentialKey == 0)
            {
                await Connection.SetTitleAsync("Exit");
            }
            else if (e.ActiveStreamers != null && sequentialKey == e.NumberOfKeys - 1 && e.ActiveStreamers.Length > pagedSequentialKey) // There is more than one page
            {
                await Connection.SetTitleAsync(">>");

                numberOfElements = e.ActiveStreamers.Length;
                numberOfKeys     = e.NumberOfKeys;
            }
            else if (e.ActiveStreamers != null && e.ActiveStreamers.Length >= pagedSequentialKey) // >= because we're doing -1 as we're starting on the second key
            {
                var streamerInfo = e.ActiveStreamers[pagedSequentialKey - 1];
                using (Image image = FetchImage(streamerInfo.PreviewImages.Template.Replace(PREVIEW_IMAGE_WIDTH_TOKEN, PREVIEW_IMAGE_WIDTH_PIXELS.ToString()).Replace(PREVIEW_IMAGE_HEIGHT_TOKEN, PREVIEW_IMAGE_HEIGHT_PIXELS.ToString())))
                {
                    await DrawStreamerImage(streamerInfo, image);
                }
                channelName = streamerInfo?.Channel?.Name;
            }
        }
Ejemplo n.º 8
0
    //ここにアクセスすると開始
    public static void Excute <T>(T obj, FlashMode flashMode = FlashMode.Out, float flashSpeed = FADE_SPEED, int howRepeat = HOW_REPEAT, bool infinityRepeat = false)
    {
        GameObject flashManager = new GameObject();

        flashManager.name = "FlashManager";
        flashManager.gameObject.AddComponent <FlashManager>();

        flashManager.GetComponent <FlashManager>().FadeStart(obj, flashMode, flashSpeed, howRepeat, infinityRepeat);
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the flash mode.
        /// </summary>
        /// <param name="flashMode">The flash mode.</param>
        protected override void SetFlashMode(FlashMode flashMode)
        {
            if (Enum <FlashMode> .Flags.IsFlagSet(_testData.SupportedFlashModes, flashMode))
            {
                // Silently go to off (according to documentation)
                _flashMode = FlashMode.Off;
            }

            _flashMode = flashMode;
        }
Ejemplo n.º 10
0
        private async void Instance_ChatMessageListChanged(object sender, ChatMessageListEventArgs e)
        {
            flashMode          = FlashMode.ChatMessage;
            channelName        = e.Channel;
            pagedSequentialKey = e.CurrentPage * (e.NumberOfKeys - NUMBER_OF_SPECIAL_KEYS) + sequentialKey; // -3 for the Exit, Back, Next buttons
            if (sequentialKey == 0)
            {
                await Connection.SetTitleAsync("Exit");
            }
            else if (e.ChatMessageKeys != null && sequentialKey == e.NumberOfKeys - 1 && e.ChatMessageKeys.Length > e.NumberOfKeys - 3) // Next key, and there is more than one page *overall*
            {
                if (e.ChatMessageKeys.Length + NUMBER_OF_SPECIAL_KEYS < pagedSequentialKey)                                             // We are on last page
                {
                    await Connection.SetTitleAsync(null);
                }
                else
                {
                    await Connection.SetTitleAsync(">>");
                }
                numberOfElements = e.ChatMessageKeys.Length;
                numberOfKeys     = e.NumberOfKeys;
            }
            else if (e.ChatMessageKeys != null && sequentialKey == e.NumberOfKeys - 2 && e.ChatMessageKeys.Length > e.NumberOfKeys - 3) // Prev key, and there is more than one page *overall*
            {
                if (sequentialKey == pagedSequentialKey)                                                                                // We are on the first page
                {
                    await Connection.SetTitleAsync(null);
                }
                else
                {
                    await Connection.SetTitleAsync("<<");
                }
                numberOfElements = e.ChatMessageKeys.Length;
                numberOfKeys     = e.NumberOfKeys;
            }
            else if (e.ChatMessageKeys != null && e.ChatMessageKeys.Length >= pagedSequentialKey) // >= because we're doing -1 as we're starting on the second key
            // +1 because starting on second key
            {
                await Connection.SetTitleAsync(null);

                var    userInfo     = e.ChatMessageKeys[pagedSequentialKey - 1];
                string userImageURL = null;
                if (!String.IsNullOrEmpty(userInfo?.KeyImageURL))
                {
                    userImageURL = userInfo.KeyImageURL.Replace(PREVIEW_IMAGE_WIDTH_TOKEN, PREVIEW_IMAGE_WIDTH_PIXELS.ToString()).Replace(PREVIEW_IMAGE_HEIGHT_TOKEN, PREVIEW_IMAGE_HEIGHT_PIXELS.ToString());
                }

                using (Image image = FetchImage(userImageURL))
                {
                    await DrawChatMessageImage(userInfo, image);
                }
                chatMessage = userInfo.ChatMessage;
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="paramode">Paramode.</param>
 public static void setFlashMode(FlashMode paramode)
 {
     if (!isPlaying())
     {
         return;
     }
     if (easyWebCamInterface != null)
     {
         easyWebCamInterface.setFocusMode((int)paramode);
     }
 }
Ejemplo n.º 12
0
 //リピートする
 void FadeRepeat()
 {
     if (flashMode == FlashMode.In)
     {
         flashMode = FlashMode.Out;
     }
     else if (flashMode == FlashMode.Out)
     {
         flashMode = FlashMode.In;
     }
     InitAlpha();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Cause the window and taskbar icon to flash
        /// </summary>
        /// <param name="hWnd">The handle for the window to flash</param>
        /// <param name="fm">Bitwise flags</param>
        /// <returns></returns>
        public static bool FlashWindow(IntPtr hWnd, FlashMode fm)
        {
            FLASHWINFO fInfo = new FLASHWINFO();

            fInfo.cbSize    = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd      = hWnd;
            fInfo.dwFlags   = (UInt32)fm;
            fInfo.uCount    = UInt32.MaxValue;
            fInfo.dwTimeout = 0;

            return(FlashWindowEx(ref fInfo));
        }
Ejemplo n.º 14
0
 private void Flash(IntPtr hwnd, FlashMode fm, int times)
 {
     unsafe
     {
         FlashInfo FI = new FlashInfo();
         FI.cd_size    = sizeof(FlashInfo);
         FI.dw_flags   = (int)fm;
         FI.dw_timeout = 0;
         FI.hwnd       = hwnd;
         FI.u_count    = times;
         FlashWindowEx(ref FI);
     }
 }
Ejemplo n.º 15
0
 private void Flash(System.IntPtr hwnd, FlashMode flashMode, int times)
 {
     unsafe
     {
         FlashInfo FlashInf = new FlashInfo();
         FlashInf.cdSize    = sizeof(FlashInfo);
         FlashInf.dwFlags   = (int)flashMode;
         FlashInf.dwTimeout = 0;
         FlashInf.hwnd      = hwnd;
         FlashInf.uCount    = times;
         FlashWindowEx(ref FlashInf);
     }
 }
Ejemplo n.º 16
0
        private async void Instance_ActiveStreamersChanged(object sender, ActiveStreamersEventArgs e)
        {
            flashMode                    = FlashMode.ActiveStreamers;
            pagedSequentialKey           = e.CurrentPage * (e.NumberOfKeys - NUMBER_OF_SPECIAL_KEYS) + sequentialKey; // -3 for the Exit, Back, Next buttons
            channelName                  = String.Empty;
            liveStreamersLongPressAction = e.LongPressAction;
            if (sequentialKey == 0)
            {
                await Connection.SetTitleAsync("Exit");
            }
            else if (e.ActiveStreamers != null && sequentialKey == e.NumberOfKeys - 1 && e.ActiveStreamers.Length > e.NumberOfKeys - 3) // Last (Next) key, and there is more than one page *overall*
            {
                if (e.ActiveStreamers.Length + NUMBER_OF_SPECIAL_KEYS < pagedSequentialKey)                                             // We are on last page
                {
                    await Connection.SetTitleAsync(null);
                }
                else
                {
                    await Connection.SetTitleAsync(">>");
                }
                numberOfElements = e.ActiveStreamers.Length;
                numberOfKeys     = e.NumberOfKeys;
            }
            else if (e.ActiveStreamers != null && sequentialKey == e.NumberOfKeys - 2 && e.ActiveStreamers.Length > e.NumberOfKeys - 3) // Prev key, and there is more than one page *overall*
            {
                if (sequentialKey == pagedSequentialKey)                                                                                // We are on the first page
                {
                    await Connection.SetTitleAsync(null);
                }
                else
                {
                    await Connection.SetTitleAsync("<<");
                }
                numberOfElements = e.ActiveStreamers.Length;
                numberOfKeys     = e.NumberOfKeys;
            }
            else if (e.ActiveStreamers != null && e.ActiveStreamers.Length >= pagedSequentialKey) // >= because we're doing -1 as we're starting on the second key
            {
                await Connection.SetTitleAsync(null);

                var streamerInfo = e.ActiveStreamers[pagedSequentialKey - 1];
                using (Image image = FetchImage(streamerInfo.PreviewImages.Template.Replace(PREVIEW_IMAGE_WIDTH_TOKEN, PREVIEW_IMAGE_WIDTH_PIXELS.ToString()).Replace(PREVIEW_IMAGE_HEIGHT_TOKEN, PREVIEW_IMAGE_HEIGHT_PIXELS.ToString())))
                {
                    await DrawStreamerImage(streamerInfo, image);
                }
                channelName = streamerInfo?.Channel?.Name;
            }
        }
Ejemplo n.º 17
0
    void Reset()
    {
        flashApplyMode = FlashMode.CanvasGroup;

#if LAYOUTPANEL
        if (GetComponent <LayoutPanel>() != null)
        {
            flashApplyMode = FlashMode.LayoutBorders;
        }
#endif
        if (name.Contains("Image"))
        {
            name = "Flasher " + name;
        }
        // if (graphic != null) flashColor = graphic.color;
        OnValidate();
    }
Ejemplo n.º 18
0
        private IGalleryObjectMetadataItem GetFlashModeMetadataItem()
        {
            IGalleryObjectMetadataItem mdi = null;
            MetadataItem rawMdi            = null;

            if (RawMetadata.TryGetValue(RawMetadataItemName.ExifFlash, out rawMdi))
            {
                if (rawMdi.ExtractedValueType == ExtractedValueType.Int64)
                {
                    FlashMode flashMode = (FlashMode)(Int64)rawMdi.Value;
                    if (MetadataEnumHelper.IsValidFlashMode(flashMode))
                    {
                        mdi = new GalleryObjectMetadataItem(int.MinValue, FormattedMetadataItemName.FlashMode, Resources.Metadata_FlashMode, flashMode.ToString(), true);
                    }
                }
            }
            return(mdi);
        }
Ejemplo n.º 19
0
        public static void FlashWindow(Window window, FlashMode mode)
        {
            FLASHWINFO fInfo = new FLASHWINFO();

            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd   = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            switch (mode)
            {
            case FlashMode.Stop:
                fInfo.dwFlags = FLASHW_STOP;
                break;

            case FlashMode.Caption:
                fInfo.dwFlags = FLASHW_CAPTION;
                break;

            case FlashMode.Tray:
                fInfo.dwFlags = FLASHW_TRAY;
                break;

            case FlashMode.All:
                fInfo.dwFlags = FLASHW_ALL;
                break;

            case FlashMode.UntilStop:
                fInfo.dwFlags = FLASHW_TIMER;
                break;

            case FlashMode.UntilForeground:
                fInfo.dwFlags = FLASHW_TIMERNOFG;
                break;
            }

            fInfo.uCount    = UInt32.MaxValue;
            fInfo.dwTimeout = 0;

            FlashWindowEx(ref fInfo);
        }
Ejemplo n.º 20
0
        //create a repeat capture
        private void createCapture(List <Surface> surfaces, FlashMode flashMode, bool repeat, CaptureRequest.Builder builder)
        {
            if (mDevice == null)
            {
                return;
            }

            //Config the flash
            if (SupportFlash())
            {
                builder.Set(CaptureRequest.FlashMode, (int)flashMode);
            }

            //Set the zoom
            builder.Set(CaptureRequest.ScalerCropRegion, getRectZoom(mCameraManager, mZoom, _id));

            //Set party mode
            builder.Set(CaptureRequest.ControlSceneMode, (int)ControlSceneMode.Hdr);

            builder.Set(CaptureRequest.ControlEffectMode, (int)_selEffect);

            //Add the targets to the builder
            foreach (var surface in surfaces)
            {
                builder.AddTarget(surface);
            }

            mCaptureBuilder = builder;
            if (repeat)
            {
                mDevice.CreateCaptureSession(surfaces, mCaptureSessionStateCallBack, mHandler);
            }
            else
            {
                mDevice.CreateCaptureSession(surfaces, mSingleCaptureSessionStateCallBack, mHandler);
            }
        }
Ejemplo n.º 21
0
    //フェードを始める
    public void FadeStart <T>(T obj, FlashMode flashMode, float flashSpeed, int howRepeat, bool infinityRepeat)
    {
        this.flashMode      = flashMode;
        this.flashSpeed     = FADE_SPEED;
        this.flashTime      = FLASH_TIME;
        this.howRepeat      = howRepeat;
        this.infinityRepeat = infinityRepeat;

        if (typeof(T) == typeof(GameObject))
        {
            targetObject   = obj as GameObject;
            componentType  = ComponentType.GameObject;
            this.flashTime = flashSpeed;
            targetObject.AddComponent <FlashManager>();
        }
        else if (typeof(T) == typeof(Image))
        {
            targetImage     = obj as Image;
            componentType   = ComponentType.Image;
            this.flashSpeed = flashSpeed;
            targetImage.gameObject.AddComponent <FlashManager>();
        }
        else if (typeof(T) == typeof(Text))
        {
            targetText      = obj as Text;
            componentType   = ComponentType.Text;
            this.flashSpeed = flashSpeed;
            targetText.gameObject.AddComponent <FlashManager>();
        }
        else
        {
            Destroy(GetComponent <FlashManager>());
        }

        isFlashStart = true;
    }
Ejemplo n.º 22
0
        private void ChandeFlashMode()
        {
            if (mFlashSupported)
            {
                int flashEnumCount = FlashMode.GetNames(typeof(FlashMode)).Length;

                int currentMode = (int)mFlashMode;

                if (currentMode + 1 == flashEnumCount)
                {
                    mFlashMode = 0;
                }
                else
                {
                    mFlashMode = (FlashMode)(currentMode + 1);
                }
                CloseCamera();
                OpenCamera(mTextureView.Width, mTextureView.Height);
            }
            else
            {
                Toast.MakeText(this, "This camera doesn`t have an itegrated flashlight", ToastLength.Short);
            }
        }
Ejemplo n.º 23
0
        //start recording video
        public void StartRecording(string file, FlashMode flashMode, int width, int heigth, int rotation)
        {
            if (mMediaRecorder != null)
            {
                return;
            }

            MediaRecorder recorder = new MediaRecorder();

            recorder.SetVideoSource(VideoSource.Surface);
            recorder.SetAudioSource(AudioSource.Mic);
            recorder.SetOutputFormat(OutputFormat.Mpeg4);
            recorder.SetOutputFile(file);
            recorder.SetVideoEncodingBitRate(6000000);
            recorder.SetVideoFrameRate(30);
            recorder.SetVideoSize(width, heigth);
            recorder.SetVideoEncoder(VideoEncoder.H264);
            recorder.SetAudioEncoder(AudioEncoder.Aac);

            recorder.SetOrientationHint(rotation);
            recorder.Prepare();

            List <Surface> surfaces = new List <Surface>();

            surfaces.Add(recorder.Surface);

            if (_TextureView != null)
            {
                surfaces.Add(getPreviewSurface());
            }

            createCapture(surfaces, flashMode, true, mDevice.CreateCaptureRequest(CameraTemplate.Record));
            recorder.Start();
            mMediaRecorder = recorder;
            mMediaFile     = file;
        }
Ejemplo n.º 24
0
        public static void FlashWindow(Window window, FlashMode mode)
        {
            FLASHWINFO fInfo = new FLASHWINFO();

            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;

            switch (mode)
            {
                case FlashMode.Stop:
                    fInfo.dwFlags = FLASHW_STOP;
                    break;
                case FlashMode.Caption:
                    fInfo.dwFlags = FLASHW_CAPTION;
                    break;
                case FlashMode.Tray:
                    fInfo.dwFlags = FLASHW_TRAY;
                    break;
                case FlashMode.All:
                    fInfo.dwFlags = FLASHW_ALL;
                    break;
                case FlashMode.UntilStop:
                    fInfo.dwFlags = FLASHW_TIMER;
                    break;
                case FlashMode.UntilForeground:
                    fInfo.dwFlags = FLASHW_TIMERNOFG;
                    break;
            }

            fInfo.uCount = UInt32.MaxValue;
            fInfo.dwTimeout = 0;

            FlashWindowEx(ref fInfo);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="flashMode">The flash mode.</param>
 protected abstract void SetFlashMode(FlashMode flashMode);
Ejemplo n.º 26
0
        /// <summary>
        /// Sets the <paramref name="flashMode"/> on the current flash control.
        /// </summary>
        /// <param name="flashMode">Flash mode.</param>
        protected void SetFlashMode(FlashMode flashMode)
        {
            if (!this.CameraController.FlashSupported)
            {
                return;
            }

            switch (flashMode)
            {
                case FlashMode.Off:
                    this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Enabled = false;
                    this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Auto    = false;
                    break;
                case FlashMode.On:
                    this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Enabled = true;
                    this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Auto    = false;
                    break;
                case FlashMode.Auto:
                    this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Enabled = true;
                    this.CameraController.MediaCapture.VideoDeviceController.FlashControl.Auto    = true;
                    break;
            }
        }
Ejemplo n.º 27
0
        /**
         * Initializing the ioctls.
         */
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mCamera = new PhotoCamera(mCameraType);
            mVideoBrush = new VideoBrush();

            runtime.RegisterCleaner(delegate()
            {
                if (null != mCamera)
                {
                    mCamera.Dispose();
                    mCamera = null;
                }
            });

            PhoneApplicationPage currentPage = (((PhoneApplicationFrame)Application.Current.RootVisual).Content as PhoneApplicationPage);

            // set the initial camera orientation in respect to the current page orientation
            SetInitialCameraOrientation(currentPage);
            // handle current page orientation and adjust the camera orientation accordingly
            HandleDeviceOrientation(currentPage);

            /**
             * Stores an output format in fmm parameter.
             * @param _index int the index of the required format.
             * @param _fmt int the momory address at which to write the output format dimensions.
             *
             * Note: the _index should be greater than 0 and smaller than the number of camera formats.
             */
            ioctls.maCameraFormat = delegate(int _index, int _fmt)
            {
                System.Windows.Size dim;
                if (GetCameraFormat(_index, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                core.GetDataMemory().WriteInt32(_fmt + MoSync.Struct.MA_CAMERA_FORMAT.width,
                    (int)dim.Width);
                core.GetDataMemory().WriteInt32(_fmt + MoSync.Struct.MA_CAMERA_FORMAT.height,
                    (int)dim.Height);

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
            * Returns the number of different output formats supported by the current device's camera.
            * \< 0 if there is no camera support.
            * 0 if there is camera support, but the format is unknown.
            */
            ioctls.maCameraFormatNumber = delegate()
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    // because the cammera is supported but not initialized, we return 0
                    return 0;
                }

                IEnumerable<System.Windows.Size> res = mCamera.AvailableResolutions;
                if (res == null) return 0;
                IEnumerator<System.Windows.Size> resolutions = res.GetEnumerator();
                resolutions.MoveNext();
                int number = 0;
                while (resolutions.Current != null)
                {
                    number++;
                    resolutions.MoveNext();
                    if (resolutions.Current == new System.Windows.Size(0, 0))
                        break;
                }
                return number;
            };

            /**
             * Starts the viewfinder and the camera
             */
            ioctls.maCameraStart = delegate()
            {
                InitCamera();

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    mCameraPrev.StartViewFinder();
                });

                return 0;
            };

            /**
             * stops the view finder and the camera.
             */
            ioctls.maCameraStop = delegate()
            {
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    mCameraPrev.StopViewFinder();
                });

                return 0;
            };

            /**
             * Adds a previewWidget to the camera controller in devices that support native UI.
             */
            ioctls.maCameraSetPreview = delegate(int _widgetHandle)
            {
                // if the camera is not initialized, we need to initialize it before
                // setting the preview
                if (!isCameraInitialized)
                {
                    InitCamera();
                }

                IWidget w = runtime.GetModule<NativeUIModule>().GetWidget(_widgetHandle);
                if (w.GetType() != typeof(MoSync.NativeUI.CameraPreview))
                {
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;
                }
                mCameraPrev = (NativeUI.CameraPreview)w;
                mCameraPrev.SetViewFinderContent(mVideoBrush);

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
             * Returns the number of available Camera on the device.
             */
            ioctls.maCameraNumber = delegate()
            {
                if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) && PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 2;
                else if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) || PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 1;
                return 0;
            };

            /**
             * Captures an image and stores it as a new data object in the
             * supplied placeholder.
             * @param _formatIndex int the required format.
             * @param _placeHolder int the placeholder used for storing the image.
             */
            ioctls.maCameraSnapshot = delegate(int _formatIndex, int _placeHolder)
            {
                AutoResetEvent are = new AutoResetEvent(false);

                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeHolder);

                        Stream data = null;
                        try
                        {
                            // as the camera always takes a snapshot in landscape left orientation,
                            // we need to rotate the resulting image 90 degrees for a current PortraitUp orientation
                            // and 180 degrees for a current LandscapeRight orientation
                            int rotateAngle = 0;
                            if (currentPage.Orientation == PageOrientation.PortraitUp)
                            {
                                rotateAngle = 90;

                            }
                            else if (currentPage.Orientation == PageOrientation.LandscapeRight)
                            {
                                rotateAngle = 180;
                            }
                            // if the current page is in a LandscapeLeft orientation, the orientation angle will be 0
                            data = RotateImage(args.ImageStream, rotateAngle);
                        }
                        catch
                        {
                            // the orientation angle was not a multiple of 90 - we keep the original image
                            data = args.ImageStream;
                        }
                        MemoryStream dataMem = new MemoryStream((int)data.Length);
                        MoSync.Util.CopySeekableStreams(data, 0, dataMem, 0, (int)data.Length);
                        res.SetInternalObject(dataMem);
                    });
                    are.Set();
                };

                mCamera.CaptureImageAvailable += mCameraSnapshotDelegate;

                mCamera.CaptureImage();

                are.WaitOne();
                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
             * Captures an image and stores it as a new data object in new
             * placeholder that is sent via #EVENT_TYPE_CAMERA_SNAPSHOT event.
             * @param _formatIndex int the required format index (size index).
             */
            ioctls.maCameraSnapshotAsync = delegate(int _formatIndex)
            {
                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                {
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;
                }

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                {
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                }

                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Stream data = null;
                        try
                        {
                            // as the camera always takes a snapshot in landscape left orientation,
                            // we need to rotate the resulting image 90 degrees for a current PortraitUp orientation
                            // and 180 degrees for a current LandscapeRight orientation
                            int rotateAngle = 0;

                            if (currentPage.Orientation == PageOrientation.PortraitUp)
                            {
                                rotateAngle = 90;
                            }
                            else if (currentPage.Orientation == PageOrientation.LandscapeRight)
                            {
                                rotateAngle = 180;
                            }
                            // if the current page is in a LandscapeLeft orientation, the orientation angle will be 0
                            data = RotateImage(args.ImageStream, rotateAngle);
                        }
                        catch
                        {
                            // the orientation angle was not a multiple of 90 - we keep the original image
                            data = args.ImageStream;
                        }

                        MemoryStream dataMem = new MemoryStream((int)data.Length);
                        MoSync.Util.CopySeekableStreams(data, 0, dataMem, 0, (int)data.Length);

                        Memory eventData = new Memory(20);

                        const int MAEventData_eventType = 0;
                        const int MAEventData_snapshotImageDataHandle = 4;
                        const int MAEventData_snapshotFormatIndex = 8;
                        const int MAEventData_snapshotImageDataRepresentation = 12;
                        const int MAEventData_snapshotReturnCode = 16;

                        eventData.WriteInt32(MAEventData_eventType, MoSync.Constants.EVENT_TYPE_CAMERA_SNAPSHOT);

                        // Create new place holder.
                        eventData.WriteInt32(MAEventData_snapshotImageDataHandle, runtime.AddResource(
                            new Resource(dataMem, MoSync.Constants.RT_BINARY, true)));
                        eventData.WriteInt32(MAEventData_snapshotFormatIndex, _formatIndex);
                        eventData.WriteInt32(MAEventData_snapshotImageDataRepresentation, MoSync.Constants.MA_IMAGE_REPRESENTATION_RAW);
                        eventData.WriteInt32(MAEventData_snapshotReturnCode, MoSync.Constants.MA_CAMERA_RES_OK);

                        runtime.PostEvent(new Event(eventData));
                    });
                };

                mCamera.CaptureImageAvailable += mCameraSnapshotDelegate;
                mCamera.CaptureImage();
                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
             * Sets the property represented by the string situated at the
             * _property address with the value situated at the _value address.
             * @param _property int the property name address
             * @param _value int the value address
             *
             * Note: the fallowing properties are not available on windows phone
             *      MA_CAMERA_FOCUS_MODE, MA_CAMERA_IMAGE_FORMAT, MA_CAMERA_ZOOM,
             *      MA_CAMERA_MAX_ZOOM.
             */
            ioctls.maCameraSetProperty = delegate(int _property, int _value)
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }

                String property = core.GetDataMemory().ReadStringAtAddress(_property);
                String value = core.GetDataMemory().ReadStringAtAddress(_value);

                if (property.Equals(MoSync.Constants.MA_CAMERA_FLASH_MODE))
                {
                    if (value.Equals(MoSync.Constants.MA_CAMERA_FLASH_ON))
                    {
                        mCamera.FlashMode = FlashMode.On;
                        mFlashMode = FlashMode.On;
                    }
                    else if (value.Equals(MoSync.Constants.MA_CAMERA_FLASH_OFF))
                    {
                        mCamera.FlashMode = FlashMode.Off;
                        mFlashMode = FlashMode.Off;
                    }
                    else if (value.Equals(MoSync.Constants.MA_CAMERA_FLASH_AUTO))
                    {
                        mCamera.FlashMode = FlashMode.Auto;
                        mFlashMode = FlashMode.Auto;
                    }
                    else return MoSync.Constants.MA_CAMERA_RES_INVALID_PROPERTY_VALUE;

                    return MoSync.Constants.MA_CAMERA_RES_OK;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_FOCUS_MODE))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_IMAGE_FORMAT))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_ZOOM))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_MAX_ZOOM))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
            };

            /**
             * Selects a camera from the avalable ones;
             * in this eigther the back or the front camera is
             * chosen
             */
            ioctls.maCameraSelect = delegate(int _camera)
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;
                }

                if ( MoSync.Constants.MA_CAMERA_CONST_BACK_CAMERA == _camera)
                {
                    if (mCamera.CameraType != CameraType.Primary)
                    {
                        mCameraType = CameraType.Primary;
                        InitCamera();
                    }
                }
                else if (MoSync.Constants.MA_CAMERA_CONST_FRONT_CAMERA == _camera)
                {
                    if (mCamera.CameraType != CameraType.FrontFacing)
                    {
                        mCameraType = CameraType.FrontFacing;
                        InitCamera();

                        MoSync.Util.RunActionOnMainThreadSync(() =>
                            {
                                SetInitialCameraOrientation(currentPage);
                            }
                        );
                    }
                }
                else return MoSync.Constants.MA_CAMERA_RES_FAILED;

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
             * Retrieves the specified property value in the given buffer.
             * @param _property int the address for the property string
             * @param _value int the address for the property value string (the buffer)
             * @param _bufSize int the buffer size
             */
            ioctls.maCameraGetProperty = delegate(int _property, int _value, int _bufSize)
            {
                String property = core.GetDataMemory().ReadStringAtAddress(_property);

                if (property.Equals(MoSync.Constants.MA_CAMERA_MAX_ZOOM))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "0",
                        _bufSize);
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_ZOOM_SUPPORTED))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "false",
                        _bufSize);
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_FLASH_SUPPORTED))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "true",
                        _bufSize);
                }
                else return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                return 0;
            };

            ioctls.maCameraRecord = delegate(int _stopStartFlag)
            {
                return MoSync.Constants.MA_CAMERA_RES_FAILED;
            };
        }
Ejemplo n.º 28
0
		private void ChangeFlashMode()
		{
			if (Flash == FlashMode.Off)
			{
				Flash = FlashMode.Torch;
				FlashImageView.SetImageResource(Resource.Drawable.flash);
			}
			else {
				Flash = FlashMode.Off;
				FlashImageView.SetImageResource(Resource.Drawable.noflash);
			}
			mPreviewBuilder.Set(CaptureRequest.FlashMode, new Java.Lang.Integer((int)Flash));
			mPreviewSession.SetRepeatingRequest(mPreviewBuilder.Build(), null, null);
		}
Ejemplo n.º 29
0
        /// <summary>
        /// Determines if the specified <see cref="FlashMode" /> is one of the defined enumerations. This method is more efficient than using
        /// <see cref="Enum.IsDefined" />, since <see cref="Enum.IsDefined" /> uses reflection.
        /// </summary>
        /// <param name="flashMode">An instance of <see cref="FlashMode" /> to test.</param>
        /// <returns>Returns true if <paramref name="flashMode"/> is one of the defined items in the enumeration; otherwise returns false.</returns>
        public static bool IsValidFlashMode(FlashMode flashMode)
        {
            switch (flashMode)
            {
                case FlashMode.FlashDidNotFire:
                case FlashMode.FlashFired:
                case FlashMode.StrobeReturnLightNotDetected:
                case FlashMode.StrobeReturnLightDetected:
                case FlashMode.FlashFiredCompulsoryFlashMode:
                case FlashMode.FlashFiredCompulsoryFlashModeReturnLightNotDetected:
                case FlashMode.FlashFiredCompulsoryFlashModeReturnLightDetected:
                case FlashMode.FlashDidNotFireCompulsoryFlashMode:
                case FlashMode.FlashDidNotFireAutoMode:
                case FlashMode.FlashFiredAutoMode:
                case FlashMode.FlashFiredAutoModeReturnLightNotDetected:
                case FlashMode.FlashFiredAutoModeReturnLightDetected:
                case FlashMode.NoFlashFunction:
                case FlashMode.FlashFiredRedEyeReductionMode:
                case FlashMode.FlashFiredRedEyeReductionModeReturnLightNotDetected:
                case FlashMode.FlashFiredRedEyeReductionModeReturnLightDetected:
                case FlashMode.FlashFiredCompulsoryFlashModeRedEyeReductionMode:
                case FlashMode.FlashFiredCompulsoryFlashModeRedEyeReductionModeReturnLightNotDetected:
                case FlashMode.FlashFiredCompulsoryFlashModeRedEyeReductionModeReturnLightDetected:
                case FlashMode.FlashFiredAutoModeRedEyeReductionMode:
                case FlashMode.FlashFiredAutoModeReturnLightNotDetectedRedEyeReductionMode:
                case FlashMode.FlashFiredAutoModeReturnLightDetectedRedEyeReductionMode:
                    break;

                default:
                    return false;
            }
            return true;
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="flashMode">The flash mode.</param>
 protected override void SetFlashMode(FlashMode flashMode)
 {
     _photoCamera.FlashMode = Enum <Microsoft.Devices.FlashMode> .ConvertFromOtherEnumValue(flashMode);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="flashMode">The flash mode.</param>
 protected abstract void SetFlashMode(FlashMode flashMode);
Ejemplo n.º 32
0
 private void Flash(System.IntPtr hwnd , FlashMode flashMode , int times)
 {
     unsafe
     {
         FlashInfo FlashInf = new FlashInfo();
         FlashInf.cdSize = sizeof(FlashInfo);
         FlashInf.dwFlags = (int)flashMode;
         FlashInf.dwTimeout = 0;
         FlashInf.hwnd = hwnd;
         FlashInf.uCount = times;
         FlashWindowEx(ref FlashInf);
     }
 }
Ejemplo n.º 33
0
 public FlashWindowMessage(object dataContext, FlashMode mode)
 {
     this.DataContext = dataContext;
     this.Mode = mode;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns>
 /// 	<c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected override bool IsFlashModeSupportedByCamera(FlashMode mode)
 {
     return _photoCamera.IsFlashModeSupported(Enum<Microsoft.Devices.FlashMode>.ConvertFromOtherEnumValue(mode));
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="flashMode">The flash mode.</param>
 protected override void SetFlashMode(FlashMode flashMode)
 {
     _photoCamera.FlashMode = Enum<Microsoft.Devices.FlashMode>.ConvertFromOtherEnumValue(flashMode);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns>
 /// 	<c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected override bool IsFlashModeSupportedByCamera(FlashMode mode)
 {
     return Enum<FlashMode>.Flags.IsFlagSet(_testData.SupportedFlashModes, mode);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns><c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.</returns>
 /// <exception cref="MustBeImplementedException"></exception>
 /// <remarks>This method is already protected and only called when the service is currently running.</remarks>
 protected override bool IsFlashModeSupportedByCamera(FlashMode mode)
 {
     throw new MustBeImplementedException();
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="flashMode">The flash mode.</param>
 /// <exception cref="MustBeImplementedException"></exception>
 protected override void SetFlashMode(FlashMode flashMode)
 {
     throw new MustBeImplementedException();
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns>
 ///     <c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected abstract bool IsFlashModeSupportedByCamera(FlashMode mode);
Ejemplo n.º 40
0
        /// <summary>
        /// Determines if the specified <see cref="FlashMode" /> is one of the defined enumerations. This method is more efficient than using
        /// <see cref="Enum.IsDefined" />, since <see cref="Enum.IsDefined" /> uses reflection.
        /// </summary>
        /// <param name="flashMode">An instance of <see cref="FlashMode" /> to test.</param>
        /// <returns>Returns true if <paramref name="flashMode"/> is one of the defined items in the enumeration; otherwise returns false.</returns>
        public static bool IsValidFlashMode(FlashMode flashMode)
        {
            switch (flashMode)
            {
                case FlashMode.Fired:
                case FlashMode.FiredAndStrobeReturned:
                case FlashMode.FiredButNoStrobeReturned:
                case FlashMode.NotFired:
                    break;

                default:
                    return false;
            }
            return true;
        }
Ejemplo n.º 41
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns>
 ///     <c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected override bool IsFlashModeSupportedByCamera(FlashMode mode)
 {
     return(_photoCamera.IsFlashModeSupported(Enum <Microsoft.Devices.FlashMode> .ConvertFromOtherEnumValue(mode)));
 }
Ejemplo n.º 42
0
            /// <summary>
            /// Set the kind of flash mode (On,Off,Auto).
            /// </summary>
            /// <param name="flashMode"></param>
            /// <param name="oResult"></param>
            public override void setFlashMode(string flashMode, IMethodResult oResult)
            {
               
                            CRhoRuntime.getInstance().logEvent("Camera class--> setFlashMode");
                            try
                            {
                                Rho_FlashMode = (FlashMode)(Rho_Flash_Types[flashMode.ToLower().Trim()]);
                                Rho_Flashmodes["flash_mode"] = flashMode.ToLower().Trim();

                            }
                            catch (Exception ex)
                            {
                                Rho_FlashMode = (FlashMode)(Rho_Flash_Types[FLASH_AUTO]);
                                CRhoRuntime.getInstance().logEvent("Camera class->invalid setFlashMode " + ex.ToString());
                            }
                        
            }
Ejemplo n.º 43
0
        /// <summary>
        /// Sets the flash mode.
        /// </summary>
        /// <param name="flashMode">The flash mode.</param>
        protected override void SetFlashMode(FlashMode flashMode)
        {
            if (Enum<FlashMode>.Flags.IsFlagSet(_testData.SupportedFlashModes, flashMode))
            {
                // Silently go to off (according to documentation)
                _flashMode = FlashMode.Off;
            }

            _flashMode = flashMode;
        }
Ejemplo n.º 44
0
            /// <summary>
            /// Set the Configuration as per parameters of camera of take Image
            /// </summary>
            /// <param name="propertyMap">Contains the details of paramenters sent by user to takepicture</param>
            private void SetCameraConfiguration(IReadOnlyDictionary<string, string> propertyMap)
            {
                CRhoRuntime.getInstance().logEvent("Camera class--> SetCameraConfiguration");
                foreach (KeyValuePair<string, string> Parameters in propertyMap)
                {
                    string ParametersKeyName = Parameters.Key.Trim().ToLower();
                    try
                    {
                        ParametersKeyName = Rho_AliasParametersName[ParametersKeyName];
                    }
                    catch (Exception ex)
                    {

                    }

                    try
                    {
                        Rho_Paramenters[ParametersKeyName] = Convert.ToDouble(Parameters.Value);
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        Rho_Flashmodes[ParametersKeyName] = Parameters.Value.ToString().Trim();
                        Rho_FlashMode = (FlashMode)(Rho_Flash_Types[Rho_Flashmodes[ParametersKeyName]]);

                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        Rho_StringParameters[ParametersKeyName] = Parameters.Value.ToString().Trim();
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        string value = Rho_OutPutFormat[ParametersKeyName];
                        string tempnumber = Rho_OutputType[Parameters.Value.Trim().ToLower()];
                        Rho_OutPutFormat.Clear();
                        Rho_OutPutFormat.Add(ParametersKeyName, Parameters.Value.Trim().ToLower());

                    }
                    catch (Exception ex)
                    {

                    }

                }

            }
Ejemplo n.º 45
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns><c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.</returns>
 /// <exception cref="MustBeImplementedException"></exception>
 /// <remarks>This method is already protected and only called when the service is currently running.</remarks>
 protected override bool IsFlashModeSupportedByCamera(FlashMode mode)
 {
     throw new MustBeImplementedException();
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Determines whether a particular flash mode is supported on the device.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <returns>
        /// 	<c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.
        /// </returns>
        public bool IsFlashModeSupported(FlashMode mode)
        {
            EnsureServiceRunning();

            return IsFlashModeSupportedByCamera(mode);
        }
Ejemplo n.º 47
0
 private void Instance_FlashStatusChanged(object sender, FlashStatusEventArgs e)
 {
     flashMode = FlashMode.Pager;
     _         = FlashImage(e.FlashMessage, e.FlashColor);
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Determines whether a particular flash mode is supported on the device.
 /// </summary>
 /// <param name="mode">The mode.</param>
 /// <returns>
 /// 	<c>true</c> if the specified flash mode is supported; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected abstract bool IsFlashModeSupportedByCamera(FlashMode mode);
Ejemplo n.º 49
0
        /**
         * Initializing the ioctls.
         */
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mCamera = new PhotoCamera(mCameraType);
            mVideoBrush = new VideoBrush();

            runtime.RegisterCleaner(delegate()
            {
                if (null != mCamera)
                {
                    mCamera.Dispose();
                    mCamera = null;
                }
            });

            // this should be set according to the orientation of
            // the device I guess.

            // we need to handle the camera orientation by hand
            PhoneApplicationPage currentPage = (((PhoneApplicationFrame)Application.Current.RootVisual).Content as PhoneApplicationPage);

            // we need to handle the initial page orientation
            double rotation = mCamera.Orientation;
            if (currentPage.Orientation == PageOrientation.LandscapeLeft)
            {
                rotation -= 90;
            }
            else if (currentPage.Orientation == PageOrientation.LandscapeRight)
            {
                rotation += 90;
            }
            mVideoBrush.RelativeTransform = new CompositeTransform()
            {
                CenterX = 0.5,
                CenterY = 0.5,
                Rotation = rotation
            };

            // on orientation changed, we need to rotate the video brush
            currentPage.OrientationChanged += new System.EventHandler<OrientationChangedEventArgs>(
                delegate(object o, OrientationChangedEventArgs args)
                {
                    rotation = mCamera.Orientation;
                    if (args.Orientation == PageOrientation.LandscapeLeft)
                    {
                        rotation -= 90;
                    }
                    else if (args.Orientation == PageOrientation.LandscapeRight)
                    {
                        rotation += 90;
                    }

                    mVideoBrush.RelativeTransform = new CompositeTransform()
                    {
                        CenterX = 0.5,
                        CenterY = 0.5,
                        Rotation = rotation
                    };
                });

            /**
             * Stores an output format in fmm parameter.
             * @param _index int the index of the required format.
             * @param _fmt int the momory address at which to write the output format dimensions.
             *
             * Note: the _index should be greater than 0 and smaller than the number of camera formats.
             */
            ioctls.maCameraFormat = delegate(int _index, int _fmt)
            {
                System.Windows.Size dim;
                if (GetCameraFormat(_index, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                core.GetDataMemory().WriteInt32(_fmt + MoSync.Struct.MA_CAMERA_FORMAT.width,
                    (int)dim.Width);
                core.GetDataMemory().WriteInt32(_fmt + MoSync.Struct.MA_CAMERA_FORMAT.height,
                    (int)dim.Height);

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
            * Returns the number of different output formats supported by the current device's camera.
            * \< 0 if there is no camera support.
            * 0 if there is camera support, but the format is unknown.
            */
            ioctls.maCameraFormatNumber = delegate()
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    // because the cammera is supported but not initialized, we return 0
                    return 0;
                }

                IEnumerable<System.Windows.Size> res = mCamera.AvailableResolutions;
                if (res == null) return 0;
                IEnumerator<System.Windows.Size> resolutions = res.GetEnumerator();
                resolutions.MoveNext();
                int number = 0;
                while (resolutions.Current != null)
                {
                    number++;
                    resolutions.MoveNext();
                    if (resolutions.Current == new System.Windows.Size(0, 0))
                        break;
                }
                return number;
            };

            /**
             * Starts the viewfinder and the camera
             */
            ioctls.maCameraStart = delegate()
            {
                initCamera();

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    mCameraPrev.StartViewFinder();
                });

                return 0;
            };

            /**
             * stops the view finder and the camera.
             */
            ioctls.maCameraStop = delegate()
            {
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    mCameraPrev.StopViewFinder();
                });

                return 0;
            };

            /**
             * Adds a previewWidget to the camera controller in devices that support native UI.
             */
            ioctls.maCameraSetPreview = delegate(int _widgetHandle)
            {
                // if the camera is not initialized, we need to initialize it before
                // setting the preview
                if (!isCameraInitialized)
                {
                    initCamera();
                }

                IWidget w = runtime.GetModule<NativeUIModule>().GetWidget(_widgetHandle);
                if (w.GetType() != typeof(MoSync.NativeUI.CameraPreview))
                {
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;
                }
                mCameraPrev = (NativeUI.CameraPreview)w;
                mCameraPrev.SetViewFinderContent(mVideoBrush);

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
             * Returns the number of available Camera on the device.
             */
            ioctls.maCameraNumber = delegate()
            {
                if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) && PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 2;
                else if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) || PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
                    return 1;
                return 0;
            };

            /**
             * Captures an image and stores it as a new data object in the
             * supplied placeholder.
             * @param _formatIndex int the required format.
             * @param _placeHolder int the placeholder used for storing the image.
             */
            ioctls.maCameraSnapshot = delegate(int _formatIndex, int _placeHolder)
            {
                AutoResetEvent are = new AutoResetEvent(false);

                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeHolder);
                        Stream data = args.ImageStream;
                        MemoryStream dataMem = new MemoryStream((int)data.Length);
                        MoSync.Util.CopySeekableStreams(data, 0, dataMem, 0, (int)data.Length);
                        res.SetInternalObject(dataMem);
                    });
                    are.Set();
                };

                mCamera.CaptureImageAvailable += mCameraSnapshotDelegate;

                mCamera.CaptureImage();

                are.WaitOne();
                return 0;
            };

            /**
             * Sets the property represented by the string situated at the
             * _property address with the value situated at the _value address.
             * @param _property int the property name address
             * @param _value int the value address
             *
             * Note: the fallowing properties are not available on windows phone
             *      MA_CAMERA_FOCUS_MODE, MA_CAMERA_IMAGE_FORMAT, MA_CAMERA_ZOOM,
             *      MA_CAMERA_MAX_ZOOM.
             */
            ioctls.maCameraSetProperty = delegate(int _property, int _value)
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }

                String property = core.GetDataMemory().ReadStringAtAddress(_property);
                String value = core.GetDataMemory().ReadStringAtAddress(_value);

                if (property.Equals(MoSync.Constants.MA_CAMERA_FLASH_MODE))
                {
                    if (value.Equals(MoSync.Constants.MA_CAMERA_FLASH_ON))
                    {
                        mCamera.FlashMode = FlashMode.On;
                        mFlashMode = FlashMode.On;
                    }
                    else if (value.Equals(MoSync.Constants.MA_CAMERA_FLASH_OFF))
                    {
                        mCamera.FlashMode = FlashMode.Off;
                        mFlashMode = FlashMode.Off;
                    }
                    else if (value.Equals(MoSync.Constants.MA_CAMERA_FLASH_AUTO))
                    {
                        mCamera.FlashMode = FlashMode.Auto;
                        mFlashMode = FlashMode.Auto;
                    }
                    else return MoSync.Constants.MA_CAMERA_RES_INVALID_PROPERTY_VALUE;

                    return MoSync.Constants.MA_CAMERA_RES_OK;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_FOCUS_MODE))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_IMAGE_FORMAT))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_ZOOM))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_MAX_ZOOM))
                {
                    return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                }
                else return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
            };

            /**
             * Selects a camera from the avalable ones;
             * in this eigther the back or the front camera is
             * chosen
             */

            ioctls.maCameraSelect = delegate(int _camera)
            {
                // if the camera is not initialized, we cannot access any of its properties
                if (!isCameraInitialized)
                {
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;
                }

                if ( MoSync.Constants.MA_CAMERA_CONST_BACK_CAMERA == _camera)
                {
                    if (mCamera.CameraType != CameraType.Primary)
                    {
                        mCameraType = CameraType.Primary;
                        initCamera();
                    }
                }
                else if (MoSync.Constants.MA_CAMERA_CONST_FRONT_CAMERA == _camera)
                {
                    if (mCamera.CameraType != CameraType.FrontFacing)
                    {
                        mCameraType = CameraType.FrontFacing;
                        initCamera();
                    }
                }
                else return MoSync.Constants.MA_CAMERA_RES_FAILED;

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            /**
             * Retrieves the specified property value in the given buffer.
             * @param _property int the address for the property string
             * @param _value int the address for the property value string (the buffer)
             * @param _bufSize int the buffer size
             */
            ioctls.maCameraGetProperty = delegate(int _property, int _value, int _bufSize)
            {
                String property = core.GetDataMemory().ReadStringAtAddress(_property);

                if (property.Equals(MoSync.Constants.MA_CAMERA_MAX_ZOOM))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "0",
                        _bufSize);
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_ZOOM_SUPPORTED))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "false",
                        _bufSize);
                }
                else if (property.Equals(MoSync.Constants.MA_CAMERA_FLASH_SUPPORTED))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "true",
                        _bufSize);
                }
                else return MoSync.Constants.MA_CAMERA_RES_PROPERTY_NOTSUPPORTED;
                return 0;
            };

            ioctls.maCameraRecord = delegate(int _stopStartFlag)
            {
                return MoSync.Constants.MA_CAMERA_RES_FAILED;
            };
        }
Ejemplo n.º 50
0
 private static void Flash(IntPtr hwnd, FlashMode flashMode, int times)
 {
     unsafe
     {
         var flashInf = new FlashInfo
         {
             CdSize = sizeof (FlashInfo),
             DwFlags = (int) flashMode,
             DwTimeout = 0,
             Hwnd = hwnd,
             UCount = times
         };
         FlashWindowEx(ref flashInf);
     }
 }
Ejemplo n.º 51
0
 /// <summary>
 /// Sets the flash mode.
 /// </summary>
 /// <param name="flashMode">The flash mode.</param>
 /// <exception cref="MustBeImplementedException"></exception>
 protected override void SetFlashMode(FlashMode flashMode)
 {
     throw new MustBeImplementedException();
 }
Ejemplo n.º 52
0
            /// <summary>
            /// Set Basic Camera style like type of camera.
            /// </summary>
            /// <param name="strId"> Front or Back camera</param>
            public void InitializeCameraProperties(string strId)
            {
              
                    double WidthofScreen = 0;
                    double HeightofScreen = 0;

                    CRhoRuntime.getInstance().logEvent("Camera class-->Entered InitializeCameraProperties ");
                    try
                    {
                        // initialize class instance in C# here
                        ApplciationBarPresentStatus = new Dictionary<bool, bool>();
                        ApplciationBarPresentStatus.Add(true, true);
                        ApplciationBarPresentStatus.Add(false, false);

                        try
                        {
                            m_CameraTypes.Clear();
                            m_CameraTypes.Add("back", 0);
                            m_CameraTypes.Add("front", 1);
                            m_CameratypeMapping.Clear();
                            m_CameratypeMapping.Add(CameraType.Primary, "back");
                            m_CameratypeMapping.Add(CameraType.FrontFacing, "front");

                            // if strid is blank select the primary //Simha
                            Rho_Camera_selected = m_CameraTypes[strId];
                        }
                        catch (Exception ex)
                        {
                            CRhoRuntime.getInstance().logEvent("Camera class->Invalid Camera type Specified, So setting to default camera(back)");
                            Rho_Camera_selected = m_CameraTypes["back"];
                        }
                        using (PhotoCamera Temp_camera = new PhotoCamera((CameraType)Rho_Camera_selected))
                        {
                            Rho_Paramenters.Add("desired_height", Temp_camera.Resolution.Height);
                            Rho_Paramenters.Add("desired_width", Temp_camera.Resolution.Width);


                            Rho_AliasParametersName.Add("desiredheight", "desired_height");
                            Rho_AliasParametersName.Add("desiredwidth", "desired_width");
                            Rho_AliasParametersName.Add("flashmode", "flash_mode");



                            Rho_Paramenters.Add("camera_type", (int)Temp_camera.CameraType);

                            Rho_StringParameters.Add("filename", "Img");
                            Rho_StringParameters.Add("imageformat", "jpg");
                            Rho_StringParameters.Add("captureSound", string.Empty);


                            Rho_OutputType.Add("image", OUTPUT_FORMAT_IMAGE);
                            Rho_OutputType.Add("datauri", OUTPUT_FORMAT_DATAURI);
                            Rho_OutPutFormat.Add("outputformat", "image");


                            //CameraResolutionhsize  what is hsize meaning in this //Simha
                            IEnumerable<Size> CameraResolutionsize = Temp_camera.AvailableResolutions;
                            // change the variable name x,y to meaning ful name
                            Rho_Paramenters.Add("getmaxwidth", CameraResolutionsize.Max(x => x.Width));
                            Rho_Paramenters.Add("getmaxheight", CameraResolutionsize.Max(Y => Y.Height));
                            int Counter = 0;
                            foreach (Size ResolutionStyle in CameraResolutionsize)
                            {
                                Rho_Screen_Resolution_Height.Add(ResolutionStyle.Height);
                                Rho_Screen_Resolution_Width.Add(ResolutionStyle.Width);
                                Rho_Supported_Resolutions.Add(Counter, ResolutionStyle);
                                Counter++;
                            }
                            Rho_MainPage = MainPage.getInstance();

                            try
                            {

                                ApplicationBarPresentStatus = ApplciationBarPresentStatus[Rho_MainPage.ApplicationBarStatus()];

                            }
                            catch (Exception ex)
                            {
                                ApplicationBarPresentStatus = true;

                            }
                            Rho_Flash_Types.Add(FLASH_ON, 1);
                            Rho_Flash_Types.Add(FLASH_OFF, 2);
                            Rho_Flash_Types.Add(FLASH_AUTO, 3);
                            Rho_Flash_Types.Add(FLASH_RED_EYE, 4);
                            Rho_FlashMode = (FlashMode)(Rho_Flash_Types[FLASH_AUTO]);
                            Rho_Flashmodes.Add("flash_mode", FLASH_AUTO);
                           
                            LayoutGrid = MainPage.LayoutGrid();

                        }
                    }
                    catch (Exception ex)
                    {
                        CRhoRuntime.getInstance().logEvent("Camera class-> InitializeCameraProperties, Setting up Camera Related Variables-->Exception" + ex.Message);

                    }
                    CameraRotation = new Dictionary<PageOrientation, Dictionary<string, double>>();

                    try
                    {
                        WidthofScreen = Application.Current.Host.Content.ActualWidth;
                        HeightofScreen = Application.Current.Host.Content.ActualHeight;
                    }
                    catch (Exception ex)
                    {
                        MainPage.LayoutGrid().Dispatcher.BeginInvoke(delegate()
                        {
                            WidthofScreen = Application.Current.Host.Content.ActualWidth;
                            HeightofScreen = Application.Current.Host.Content.ActualHeight;
                        });
                        while (WidthofScreen == 0)
                        {
                            Thread.Sleep(1000);
                        }
                    }
                    Dictionary<string, double> LandscapeLeft = new Dictionary<string, double>();

                    LandscapeLeft.Add("rotation", -90);
                    LandscapeLeft.Add("Height", WidthofScreen);
                    LandscapeLeft.Add("Width", HeightofScreen);
                    LandscapeLeft.Add("CameraType", 0);

                    CameraRotation.Add(PageOrientation.LandscapeLeft, LandscapeLeft);



                    Dictionary<string, double> LandscapeRight = new Dictionary<string, double>();
                    LandscapeRight.Add("rotation", 90);
                    LandscapeRight.Add("Height", WidthofScreen);
                    LandscapeRight.Add("Width", HeightofScreen);

                    CameraRotation.Add(PageOrientation.LandscapeRight, LandscapeRight);



                    Dictionary<string, double> PortraitDown = new Dictionary<string, double>();
                    PortraitDown.Add("rotation", 0);
                    PortraitDown.Add("Height", HeightofScreen);
                    PortraitDown.Add("Width", WidthofScreen);
                    PortraitDown.Add("front", -180);

                    CameraRotation.Add(PageOrientation.PortraitDown, PortraitDown);

                    Dictionary<string, double> PortraitUp = new Dictionary<string, double>();
                    PortraitUp.Add("rotation", 0);
                    PortraitUp.Add("Height", HeightofScreen);
                    PortraitUp.Add("Width", WidthofScreen);
                    PortraitUp.Add("front", 180);

                    CameraRotation.Add(PageOrientation.PortraitUp, PortraitUp);
                    CRhoRuntime.getInstance().logEvent("Camera class-->End InitializeCameraProperties");



            
              
            }