Exemple #1
0
        private void CropImage()
        {
            var croppedFile    = CreateTempFile(_cacheDir, "cropped");
            var destinationUri = AndroidUri.FromFile(croppedFile);
            var options        = new UCrop.Options();

            // applying UI theme
            options.SetToolbarColor(ContextCompat.GetColor(this, Resource.Color.colorPrimary));
            options.SetStatusBarColor(ContextCompat.GetColor(this, Resource.Color.colorPrimary));
            options.SetActiveControlsWidgetColor(ContextCompat.GetColor(this, Resource.Color.colorPrimary));
            options.WithAspectRatio(1, 1);
            options.WithMaxResultSize(2000, 2000);
            options.SetCompressionQuality(80);

            UCrop.Of(_photoUri, destinationUri)
            .WithOptions(options)
            .Start(this);
        }
Exemple #2
0
        /// <summary>
        /// Launches the photo cropper.
        /// </summary>
        /// <param name="sourceUri">The URI of the source image.</param>
        /// <param name="activity">An <see cref="Activity"/> to use to obtain resources.</param>
        /// <returns>The URI where the cropped image will be saved.</returns>
        public static AndroidUri LaunchPhotoCropper(AndroidUri sourceUri, Activity activity)
        {
            File       dest    = new File(activity.CacheDir, FILENAME_CROPPED_IMAGE);
            AndroidUri destUri = AndroidUri.FromFile(dest);

            UCrop.Options options = new UCrop.Options();
            options.SetCompressionFormat(Bitmap.CompressFormat.Png);
            options.SetToolbarColor(ContextCompat.GetColor(activity, Resource.Color.color_primary));
            options.SetStatusBarColor(ContextCompat.GetColor(activity, Resource.Color.color_primary_dark));
            options.SetActiveWidgetColor(ContextCompat.GetColor(activity, Resource.Color.color_accent));
            options.SetToolbarTitle(activity.GetString(Resource.String.crop_title));

            UCrop.Of(sourceUri, destUri)
            .WithAspectRatio(1, 1)
            .WithOptions(options)
            .Start(activity);

            return(destUri);
        }
        private void CropImage(Uri selectedImageURI)
        {
            Uri destinationUri = Uri.FromFile(new File(Context.CacheDir, QueryName(Context.ContentResolver, selectedImageURI)));

            UCrop.Options options = new UCrop.Options();
            options.SetCompressionQuality(IMAGE_COMPRESSION);
            options.SetToolbarColor(ContextCompat.GetColor(Context, Resource.Color.colorPrimary));
            options.SetStatusBarColor(ContextCompat.GetColor(Context, Resource.Color.colorPrimaryDark));
            options.SetActiveControlsWidgetColor(ContextCompat.GetColor(Context, Resource.Color.colorAccent));

            if (lockAspectRatio)
            {
                options.WithAspectRatio(ASPECT_RATIO_X, ASPECT_RATIO_Y);
            }

            if (setBitmapMaxWidthHeight)
            {
                options.WithMaxResultSize(bitmapMaxWidth, bitmapMaxHeight);
            }

            UCrop.Of(selectedImageURI, destinationUri)
            .WithOptions(options)
            .Start(Context, this, UCROP_REQUEST);
        }
        private UCrop AdvancedConfig(UCrop uCrop)
        {
            UCrop.Options options = new UCrop.Options();

            switch (mRadioGroupCompressionSettings.CheckedRadioButtonId)
            {
            case Resource.Id.radio_png:
                options.SetCompressionFormat(Bitmap.CompressFormat.Png);

                break;

            case Resource.Id.radio_jpeg:

            default:
                options.SetCompressionFormat(Bitmap.CompressFormat.Jpeg);

                break;
            }
            options.SetCompressionQuality(mSeekBarQuality.Progress);

            options.SetHideBottomControls(mCheckBoxHideBottomControls.Checked);
            options.SetFreeStyleCropEnabled(mCheckBoxFreeStyleCrop.Checked);

            /*
             * If you want to configure how gestures work for all UCropActivity tabs
             *
             * options.SetAllowedGestures(UCropActivity.Scale, UCropActivity.Rotate, UCropActivity.All);
             *
             * */

            /*
             * This sets max size for bitmap that will be decoded from source Uri.
             * More size - more memory allocation, default implementation uses screen diagonal.
             *
             * options.SetMaxBitmapSize(640);
             *
             * */


            /*
             *
             * Tune everything
             *
             * options.SetMaxScaleMultiplier(5);
             * options.SetImageToCropBoundsAnimDuration(666);
             * options.SetDimmedLayerColor(Color.Cyan);
             * options.SetCircleDimmedLayer(true);
             * options.SetShowCropFrame(false);
             * options.SetCropGridStrokeWidth(20);
             * options.SetCropGridColor(Color.Green);
             * options.SetCropGridColumnCount(2);
             * options.SetCropGridRowCount(1);
             *
             * // not found two below methods
             * //options.SetToolbarCropDrawable(Resource.Drawable.your_crop_icon);
             * //options.SetToolbarCancelDrawable(Resource.Drawable.your_cancel_icon);
             *
             * // Color palette
             * //options.SetToolbarColor(ContextCompat.GetColor(this, Resource.Color.your_color_res));
             * //options.SetStatusBarColor(ContextCompat.GetColor(this, Resource.Color.your_color_res));
             * //options.SetActiveWidgetColor(ContextCompat.GetColor(this, Resource.Color.your_color_res));
             * //options.SetToolbarWidgetColor(ContextCompat.GetColor(this, Resource.Color.your_color_res));
             *
             * // not found the below method
             * //options.SetRootViewBackgroundColor(ContextCompat.getColor(this, R.color.your_color_res));
             *
             * // Aspect ratio options
             * options.SetAspectRatioOptions(1,
             *   new AspectRatio("WOW", 1, 2),
             *   new AspectRatio("MUCH", 3, 4),
             *   new AspectRatio("RATIO", CropImageView.DefaultAspectRatio, CropImageView.DefaultAspectRatio),
             *   new AspectRatio("SO", 16, 9),
             *   new AspectRatio("ASPECT", 1, 1));
             *
             */

            return(uCrop.WithOptions(options));
        }
 public UCrop.Options UCropOptions()
 {
     UCrop.Options options = new UCrop.Options();
     options.SetHideBottomControls(true);
     return(options);
 }