/** * Set the options of the crop image view to the given values. */ public void setCropImageViewOptions(CropImageViewOptions options) { mCropImageView.SetScaleType(options.scaleType); mCropImageView.SetCropShape(options.cropShape); mCropImageView.SetGuidelines(options.guidelines); mCropImageView.SetAspectRatio((int)options.aspectRatio.First, (int)options.aspectRatio.Second); mCropImageView.SetFixedAspectRatio(options.fixAspectRatio); mCropImageView.ShowCropOverlay = options.showCropOverlay; mCropImageView.ShowProgressBar = options.showProgressBar; mCropImageView.AutoZoomEnabled = options.autoZoomEnabled; mCropImageView.MaxZoom = options.maxZoomLevel; }
private CropImageView CreateImageView(CropView page) { var cropImageView = new CropImageView(Context) { LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent) }; cropImageView.SetAspectRatio(1, 1); cropImageView.SetImageBitmap(BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length)); return(cropImageView); }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); var page = Element as CropView; if (page != null) { var cropImageView = new CropImageView(Context); cropImageView.AutoZoomEnabled = false; //cropImageView.SetMinCropResultSize(200, 200); //cropImageView.SetMaxCropResultSize(300, 300); cropImageView.SetAspectRatio(1, 1); cropImageView.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); Bitmap bitmp = BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length); cropImageView.SetImageBitmap(bitmp); var stackLayout = new StackLayout { Children = { cropImageView } }; var rotateButton = new Xamarin.Forms.Button { Text = "旋轉" }; rotateButton.Clicked += (sender, ex) => { cropImageView.RotateImage(90); }; stackLayout.Children.Add(rotateButton); var finishButton = new Xamarin.Forms.Button { Text = "完成" }; finishButton.Clicked += (sender, ex) => { Bitmap cropped = cropImageView.CroppedImage; using (MemoryStream memory = new MemoryStream()) { cropped.Compress(Bitmap.CompressFormat.Png, 100, memory); XFImgCrop.App.CroppedImage = memory.ToArray(); } page.DidCrop = true; page.Navigation.PopModalAsync(); }; stackLayout.Children.Add(finishButton); page.Content = stackLayout; } }
/** * Set the options of the crop image view to the given values. */ public void SetCropImageViewOptions(CropImageViewOptions options) { _cropImageView.SetScaleType(options.ScaleType); _cropImageView.SetCropShape(options.CropShape); _cropImageView.SetGuidelines(options.Guidelines); _cropImageView.SetAspectRatio(options.AspectRatio.AspectRatioX, options.AspectRatio.AspectRatioY); _cropImageView.SetFixedAspectRatio(options.FixAspectRatio); _cropImageView.SetMultiTouchEnabled(options.Multitouch); _cropImageView.ShowCropOverlay = options.ShowCropOverlay; _cropImageView.ShowProgressBar = options.ShowProgressBar; _cropImageView.AutoZoomEnabled = options.AutoZoomEnabled; _cropImageView.MaxZoom = options.MaxZoomLevel; _cropImageView.FlippedHorizontally = options.FlipHorizontally; _cropImageView.FlippedVertically = options.FlipVertically; }
public void SetCropImageViewOptions(CropImageViewOptions options) { mCropImageView.SetScaleType(options.scaleType); mCropImageView.SetCropShape(options.cropShape); mCropImageView.SetGuidelines(options.guidelines); mCropImageView.SetAspectRatio(options.aspectRatio.Item1, options.aspectRatio.Item2); mCropImageView.SetFixedAspectRatio(options.fixAspectRatio); mCropImageView.SetMultiTouchEnabled(options.multitouch); mCropImageView.ShowCropOverlay = (options.showCropOverlay); mCropImageView.ShowProgressBar = (options.showProgressBar); mCropImageView.AutoZoomEnabled = (options.autoZoomEnabled); mCropImageView.MaxZoom = (options.maxZoomLevel); mCropImageView.FlippedHorizontally = (options.flipHorizontally); mCropImageView.FlippedVertically = (options.flipVertically); }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.activity_main); // Sets fonts for all Typeface mFont = Typeface.CreateFromAsset(Assets, "Roboto-Thin.ttf"); var root = FindViewById <ViewGroup>(Resource.Id.mylayout); SetFont(root, mFont); // Initialize components of the app cropImageView = FindViewById <CropImageView>(Resource.Id.CropImageView); var showGuidelinesSpin = FindViewById <Spinner>(Resource.Id.showGuidelinesSpin); // Set initial spinner value showGuidelinesSpin.SetSelection(ON_TOUCH); //Set AspectRatio fixed for circular selection cropImageView.SetFixedAspectRatio(true); // Sets initial aspect ratio to 10/10 cropImageView.SetAspectRatio(DEFAULT_ASPECT_RATIO_VALUES, DEFAULT_ASPECT_RATIO_VALUES); //Sets the rotate button var rotateButton = FindViewById <Button>(Resource.Id.Button_rotate); rotateButton.Click += delegate { cropImageView.RotateImage(ROTATE_NINETY_DEGREES); }; // Sets up the Spinner showGuidelinesSpin.ItemSelected += showGuidelinesSpin_ItemSelected; showGuidelinesSpin.NothingSelected += showGuidelinesSpin_NothingSelected; var cropButton = FindViewById <Button>(Resource.Id.Button_crop); cropButton.Click += delegate { croppedImage = cropImageView.GetCroppedCircleImage(); var croppedImageView = FindViewById <ImageView>(Resource.Id.croppedImageView); croppedImageView.SetImageBitmap(croppedImage); }; } catch (Exception ex) { ex.ToString(); } }