Beispiel #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);
        }
Beispiel #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);
        }