示例#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();
        }
示例#2
0
        /// <summary>
        /// Setup the base matrix 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);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(Android.Views.WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.cropimage);

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

            showStorageToast(this);

            Bundle 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();
                return;
            }

            Window.AddFlags(WindowManagerFlags.Fullscreen);


            FindViewById <Button>(Resource.Id.discard).Click += (sender, e) => { SetResult(Result.Canceled); Finish(); };
            FindViewById <Button>(Resource.Id.save).Click    += (sender, e) => { onSaveClicked(); };

            FindViewById <Button>(Resource.Id.rotateLeft).Click += (o, e) =>
            {
                bitmap = Util.rotateImage(bitmap, -90);
                RotateBitmap rotateBitmap = new RotateBitmap(bitmap);
                imageView.SetImageRotateBitmapResetBase(rotateBitmap, true);
                addHighlightView();
            };

            FindViewById <Button>(Resource.Id.rotateRight).Click += (o, e) =>
            {
                bitmap = Util.rotateImage(bitmap, 90);
                RotateBitmap rotateBitmap = new RotateBitmap(bitmap);
                imageView.SetImageRotateBitmapResetBase(rotateBitmap, true);
                addHighlightView();
            };

            imageView.SetImageBitmapResetBase(bitmap, true);
            addHighlightView();
        }