// Optional parameters for calling this method from viewHolder public void StartCropActivity(Android.Net.Uri uri, Activity context = null, int pressedPhotoPos = 0) { UCrop uCrop; _pressedPhotoPosition = pressedPhotoPos; if (context != null) { uCrop = UCrop.Of(uri, Android.Net.Uri.FromFile(new Java.IO.File(context.CacheDir, Constants.destinationFileName))); } else { uCrop = UCrop.Of(uri, Android.Net.Uri.FromFile(new Java.IO.File(CacheDir, Constants.destinationFileName))); } uCrop.WithAspectRatio(1, 1); uCrop.WithOptions(_nativeMethods.UCropOptions()); if (context != null) { uCrop.Start(context); } else { uCrop.Start(this); } }
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); }
/// <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 StartCropActivity(Android.Net.Uri uri) { string destinationFileName = SAMPLE_CROPPED_IMAGE_NAME; switch (mRadioGroupCompressionSettings.CheckedRadioButtonId) { case Resource.Id.radio_png: destinationFileName += ".png"; break; case Resource.Id.radio_jpeg: destinationFileName += ".jpg"; break; } UCrop uCrop = UCrop.Of(uri, Android.Net.Uri.FromFile(new Java.IO.File(CacheDir, destinationFileName))); uCrop = BasisConfig(uCrop); uCrop = AdvancedConfig(uCrop); uCrop.Start(this); }
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); }