Esempio n. 1
0
        public void SetImageRotateBitmapResetBase(RotateBitmap bitmap, bool resetSupp)
        {
            int viewWidth = Width;

            if (viewWidth <= 0)
            {
                onLayoutRunnable = () =>
                {
                    SetImageRotateBitmapResetBase(bitmap, resetSupp);
                };

                return;
            }

            if (bitmap.Bitmap != null)
            {
                GetProperBaseMatrix(bitmap, baseMatrix);
                setImageBitmap(bitmap.Bitmap, bitmap.Rotation);
            }
            else
            {
                baseMatrix.Reset();
                base.SetImageBitmap(null);
            }

            if (resetSupp)
            {
                suppMatrix.Reset();
            }
            ImageMatrix  = GetImageViewMatrix();
            this.maxZoom = CalculateMaxZoom();
        }
Esempio n. 2
0
        /// <summary>
        /// Setup the base MatrixImage so that the image is centered and scaled properly.
        /// </summary>
        private void GetProperBaseMatrix(RotateBitmap bitmap, Matrix matrix)
        {
            float viewWidth  = Width;
            float viewHeight = Height;

            float w        = bitmap.Width;
            float h        = bitmap.Height;
            int   rotation = bitmap.Rotation;

            matrix.Reset();

            // We limit up-scaling to 2x otherwise the result may look bad if it's
            // a small icon.
            float widthScale  = Math.Min(viewWidth / w, 2.0f);
            float heightScale = Math.Min(viewHeight / h, 2.0f);
            float scale       = Math.Min(widthScale, heightScale);

            matrix.PostConcat(bitmap.GetRotateMatrix());
            matrix.PostScale(scale, scale);

            matrix.PostTranslate(
                (viewWidth - w * scale) / 2F,
                (viewHeight - h * scale) / 2F);
        }
Esempio n. 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.cropimage);

            _imageView = FindViewById <CropImageView>(Resource.Id.image);

            ShowStorageToast(this);

            var extras = Intent.Extras;

            if (extras != null)
            {
                _imagePath = extras.GetString("image-path");

                _saveUri = GetImageUri(_imagePath);
                if (extras.GetString(MediaStore.ExtraOutput) != null)
                {
                    _saveUri = GetImageUri(extras.GetString(MediaStore.ExtraOutput));
                }

                _bitmap = GetBitmap(_imagePath);

                _aspectX = extras.GetInt("aspectX");
                _aspectY = extras.GetInt("aspectY");
                _outputX = extras.GetInt("outputX");
                _outputY = extras.GetInt("outputY");
                _scale   = extras.GetBoolean("scale", true);
                _scaleUp = extras.GetBoolean("scaleUpIfNeeded", true);

                if (extras.GetString("outputFormat") != null)
                {
                    _outputFormat = Bitmap.CompressFormat.ValueOf(extras.GetString("outputFormat"));
                }
            }

            if (_bitmap == null)
            {
                Finish();
                //raise event
                MediaCroped?.Invoke(this, new XViewEventArgs(nameof(MediaCroped), null));
                return;
            }

            Window.AddFlags(WindowManagerFlags.Fullscreen);


            FindViewById <Button>(Resource.Id.discard).Click += (sender, e) => { OnDisCardClick(); };
            FindViewById <Button>(Resource.Id.save).Click    += (sender, e) => { OnSaveClicked(); };

            FindViewById <Button>(Resource.Id.rotateLeft).Click += (o, e) =>
            {
                _bitmap = Util.RotateImage(_bitmap, -90);
                var rotateBitmap = new RotateBitmap(_bitmap);
                _imageView.SetImageRotateBitmapResetBase(rotateBitmap, true);
                AddHighlightView();
            };

            FindViewById <Button>(Resource.Id.rotateRight).Click += (o, e) =>
            {
                _bitmap = Util.RotateImage(_bitmap, 90);
                var rotateBitmap = new RotateBitmap(_bitmap);
                _imageView.SetImageRotateBitmapResetBase(rotateBitmap, true);
                AddHighlightView();
            };

            _imageView.SetImageBitmapResetBase(_bitmap, true);
            AddHighlightView();
        }