Ejemplo n.º 1
0
        public static PixelFormat ToInterop(ANDROIDGFX.Format fmt, PixelFormat?defFmt = null)
        {
            switch (fmt)
            {
            case ANDROIDGFX.Format.A8: return(Pixel.Alpha8.Format);

            case ANDROIDGFX.Format.L8: return(Pixel.Luminance8.Format);

            case ANDROIDGFX.Format.Rgb565: return(Pixel.BGR565.Format);

            case ANDROIDGFX.Format.Rgba4444: return(Pixel.BGRA4444.Format);

            case ANDROIDGFX.Format.Rgb888: return(Pixel.RGB24.Format);

            case ANDROIDGFX.Format.Rgba8888: return(Pixel.RGBA32.Format);

            default: if (defFmt.HasValue)
                {
                    return(defFmt.Value);
                }
                break;
            }

            throw new Diagnostics.PixelFormatNotSupportedException(fmt, nameof(fmt));
        }
Ejemplo n.º 2
0
        void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height)
        {
            var surfaceRect = holder.SurfaceFrame;

            Size = new System.Drawing.Size(surfaceRect.Right - surfaceRect.Left, surfaceRect.Bottom - surfaceRect.Top);
            // We don't use Display's rotation to determine orientation because it shows rotation
            // from "natural" orientation. On some devices 0 degrees may refer to portrait and on some devices
            // 0 degrees may refer to landscape.
            DeviceOrientation orientation;

            using (var realSize = new Android.Graphics.Point()) {
                // On some tablets Surface may be created twice after resuming game if orientation is restricted -
                // For example if you use tablet in landscape and game is restricted to portrait,
                // surface will be created for landscape and on a next frame recreated for portrait.
                // So we prefer to use Display's Real Size which seems always follow restricted orientation.
                windowManager.DefaultDisplay.GetRealSize(realSize);
                orientation = realSize.X < realSize.Y ? DeviceOrientation.Portrait : DeviceOrientation.LandscapeLeft;
            }
            var deviceRotated = Application.CurrentDeviceOrientation != orientation;

            Application.CurrentDeviceOrientation = orientation;
            Resize?.Invoke(this, new ResizeEventArgs {
                DeviceRotated = deviceRotated
            });
        }
Ejemplo n.º 3
0
        public static bool TryGetPixelFormat(ANDROIDGFX.Format src, bool srcIsPremultiplied, out PixelFormat dst)
        {
            if (srcIsPremultiplied)
            {
                throw new Diagnostics.PixelFormatNotSupportedException(src, nameof(src));
            }

            switch (src)
            {
            case ANDROIDGFX.Format.A8: dst = Pixel.Alpha8.Format; return(true);

            case ANDROIDGFX.Format.L8: dst = Pixel.Luminance8.Format; return(true);

            case ANDROIDGFX.Format.Rgb565: dst = Pixel.BGR565.Format; return(true);

            case ANDROIDGFX.Format.Rgba4444: dst = Pixel.BGRA4444.Format; return(true);

            case ANDROIDGFX.Format.Rgb888: dst = Pixel.RGB24.Format; return(true);

            case ANDROIDGFX.Format.Rgba8888: dst = Pixel.RGBA32.Format; return(true);
            }

            dst = default;
            return(false);
        }
Ejemplo n.º 4
0
        public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height)
        {
            if (_holder == null || _camera == null)
            {
                return;
            }

            try
            {
                _camera.StopPreview();
            }
            catch (Java.Lang.Exception e)
            {
                e.PrintStackTrace();
            }

            SetCameraDisplayOrientation();

            try
            {
                _camera.SetPreviewDisplay(holder);
                _camera.StartPreview();
            }
            catch (Java.Lang.Exception e)
            {
                e.PrintStackTrace();
            }
        }
Ejemplo n.º 5
0
 public static ImageFormat ToXwt(this AG.Format value)
 {
     if (value == AG.Format.Rgba8888)
     {
         return(ImageFormat.ARGB32);
     }
     throw new ArgumentException();
 }
Ejemplo n.º 6
0
 public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h)
 {
     // Now that the size is known, set up the camera parameters and begin
     // the preview.
     if (mTransparentView.Holder == holder)
     {
         DrawFocusRect(holder, L, T, R, B, Android.Graphics.Color.Yellow);
     }
 }
Ejemplo n.º 7
0
        public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h)
        {
            // Now that the size is known, set up the camera parameters and begin
            // the preview.
            Camera.Parameters parameters = mCamera.GetParameters();
            parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height);
            RequestLayout();

            mCamera.SetParameters(parameters);
            mCamera.StartPreview();
        }
Ejemplo n.º 8
0
        public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height)
        {
            // Measure and layout the view with the canvas dimensions.
            int measuredWidth  = View.MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly);
            int measuredHeight = View.MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly);

            countDownView.Measure(measuredWidth, measuredHeight);
            countDownView.Layout(
                0, 0, countDownView.MeasuredWidth, countDownView.MeasuredHeight);

            chronometerView.Measure(measuredWidth, measuredHeight);
            chronometerView.Layout(
                0, 0, chronometerView.MeasuredWidth, chronometerView.MeasuredHeight);
        }
        public void SurfaceChanged(ISurfaceHolder arg0, Android.Graphics.Format arg1, int arg2, int arg3)
        {
            //get camera parameters
            parameters = mCamera.GetParameters();

            //set camera parameters
            mCamera.SetParameters(parameters);

            //mCamera.SetDisplayOrientation (90);
            mCamera.StartPreview();

            //Take the picture
            mCamera.TakePicture(null, null, this);
            //Log.Debug ("","picture taken!!!");
        }
Ejemplo n.º 10
0
        public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h)
        {
            // Now that the size is known, set up the camera parameters and begin
            // the preview.
            //Android.Hardware.Camera.Parameters parameters = PreviewCamera.GetParameters();
            //parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height);
            //RequestLayout();

            //PreviewCamera.SetParameters(parameters);
            //PreviewCamera.StartPreview();
            //if (mSupportedPreviewSizes != null)
            //{
            //    mPreviewSize = _Context.GetOptimalPreviewSize(mSupportedPreviewSizes);
            //}
            if (_camera == null)
            {
                return;
            }
            if (_Context.previewing)
            {
                //_camera.StopPreview();
                //_Context.previewing = false;
                if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape)
                {
                    _camera.SetDisplayOrientation(90);
                    //Android.Hardware.Camera.Size cameraSize = _camera.GetParameters().PictureSize;
                    //int wr = relativeLayout.Width;
                    //int hr = relativeLayout.Height;
                    //float ratio = relativeLayout.Width * 1f / cameraSize.Height;
                    //w = cameraSize.Width * ratio;
                    //h = cameraSize.Height * ratio;
                    //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)h, (int)w);
                    //cameraSurfaceView.LayoutParameters = (lp);
                }
                else
                {
                    _camera.SetDisplayOrientation(0);
                    //Android.Hardware.Camera.Size cameraSize = camera.GetParameters().PictureSize;
                    //float ratio = relativeLayout.Height * 1f / cameraSize.Height;
                    //w = cameraSize.Width * ratio;
                    //h = cameraSize.Height * ratio;
                    //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)w, (int)h);
                    //cameraSurfaceView.LayoutParameters = (lp);
                }
                return;
            }
            try
            {
                //float w = 0;
                //float h = 0;
                if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape)
                {
                    _camera.SetDisplayOrientation(90);
                    //Android.Hardware.Camera.Size cameraSize = _camera.GetParameters().PictureSize;
                    //int wr = relativeLayout.Width;
                    //int hr = relativeLayout.Height;
                    //float ratio = relativeLayout.Width * 1f / cameraSize.Height;
                    //w = cameraSize.Width * ratio;
                    //h = cameraSize.Height * ratio;
                    //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)h, (int)w);
                    //cameraSurfaceView.LayoutParameters = (lp);
                }
                else
                {
                    _camera.SetDisplayOrientation(0);
                    //Android.Hardware.Camera.Size cameraSize = camera.GetParameters().PictureSize;
                    //float ratio = relativeLayout.Height * 1f / cameraSize.Height;
                    //w = cameraSize.Width * ratio;
                    //h = cameraSize.Height * ratio;
                    //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)w, (int)h);
                    //cameraSurfaceView.LayoutParameters = (lp);
                }
                //camera.SetPreviewDisplay(cameraSurfaceHolder);
                //camera.StartPreview();

                Android.Hardware.Camera.Parameters parameters = PreviewCamera.GetParameters();
                parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height);
                Console.WriteLine("Param mPreviewSize.Width:" + mPreviewSize.Width + " mPreviewSize.height:" + mPreviewSize.Height);
                RequestLayout();
                parameters.SetPictureSize(mPreviewSize.Width, mPreviewSize.Height);
                parameters.JpegQuality   = (100);
                parameters.PictureFormat = (ImageFormat.Jpeg);



                PreviewCamera.SetParameters(parameters);
                PreviewCamera.GetParameters().FocusMode = Android.Hardware.Camera.Parameters.FocusModeAuto;
                if (PreviewCamera.GetParameters().IsZoomSupported)
                {
                    PreviewCamera.GetParameters().Zoom = (0);
                }
                PreviewCamera.StartPreview();
                _Context.previewing = true;
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("SurfaceChanged:" + e.ToString());
            }
        }
Ejemplo n.º 11
0
 public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height)
 {
 }
Ejemplo n.º 12
0
 public static PixelFormat ToInterop(this ANDROIDGFX.Format fmt, PixelFormat?defFmt = null)
 {
     return(_Implementation.ToInterop(fmt, defFmt));
 }
Ejemplo n.º 13
0
 public void surfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h)
 {
     base.SurfaceChanged(holder, format, w, h);
 }
Ejemplo n.º 14
0
 public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
 {
     SetCameraDisplayOrientation(_cameraId);
 }
Ejemplo n.º 15
0
 public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h)
 {
     Console.WriteLine("SurfaceChanged");
 }