private static Button CreateOkButton(CropView page, CropImageView view, string buttonText)
        {
            var button = new Button
            {
                Text   = buttonText,
                Style  = Application.Current.Resources["ActionButton"] as Style,
                Margin = ButtonMargin
            };

            button.Clicked += (sender, ex) =>
            {
                var cropped = view.CroppedImage;
                using (var memory = new MemoryStream())
                {
                    cropped.Compress(Bitmap.CompressFormat.Jpeg, 100, memory);
                    page.CroppedImage = memory.ToArray();
                }

                page.IsCropped = true;
                page.Navigation.PopModalAsync();
            };

            return(button);
        }
Example #2
0
 public void OnCropImageComplete(CropImageView view, CropImageView.CropResult result)
 {
     HandleCropResult(result);
 }
Example #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);
            var page = Element as CropView;

            if (page != null)
            {
                var cropImageView = new CropImageView(Context);
                cropImageView.LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
                Bitmap bitmp = BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length);
                cropImageView.SetImageBitmap(bitmp);

                var scrollView = new ScrollView
                {
                    Content           = cropImageView.ToView(),
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };



                var stackLayout = new StackLayout
                {
                    Children          = { scrollView },
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };



                var rotateButton = new Button {
                    Text = Translator.getText("Rotate")
                };

                rotateButton.Clicked += (sender, ex) =>
                {
                    cropImageView.RotateImage(90);
                };
                //stackLayout.Children.Add(rotateButton);

                var finishButton = new Button {
                    Text = Translator.getText("Finish")
                };

                finishButton.Clicked += (sender, ex) =>
                {
                    Bitmap cropped = cropImageView.CroppedImage;


                    using (MemoryStream memory = new MemoryStream())
                    {
                        UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);
                        cropped.Compress(Bitmap.CompressFormat.Png, 60, memory);
                        App.CroppedImage = memory.ToArray();
                        UserDialogs.Instance.HideLoading();
                    }
                    page.DidCrop = true;

                    page.Navigation.PopModalAsync();
                };

                //stackLayout.Children.Add(finishButton);

                Grid grid = new Grid
                {
                    VerticalOptions = LayoutOptions.Fill,
                    Padding         = 5,
                    RowSpacing      = 2,
                };

                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Star
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Star
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = 43
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = 43
                });

                grid.Children.Add(stackLayout, 0, 0);
                grid.Children.Add(rotateButton, 0, 1);
                grid.Children.Add(finishButton, 0, 2);

                page.Content = grid;
            }
        }
Example #4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);
            var page = Element as CropView;

            if (page != null)
            {
                var cropImageView = new CropImageView(Context);
                cropImageView.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

                BitmapFactory.Options options = new BitmapFactory.Options();
                options.InSampleSize = 2;


                Bitmap bitmp = BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length, options);


                cropImageView.SetImageBitmap(bitmp);
                cropImageView.SetMaxCropResultSize(Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Width), Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Height));
                cropImageView.SetMinCropResultSize(Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Width) / 4, Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Height) / 4);
                cropImageView.SetMinimumHeight(Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Height) / 2);
                cropImageView.SetMinimumWidth(Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Width) / 2);

                var scrollView = new ScrollView {
                    Content = cropImageView.ToView()
                };
                var stackLayout = new StackLayout {
                    Children = { scrollView }
                };

                var rotateButton = new Button {
                    Text = "Rotate"
                };
                rotateButton.CornerRadius = 50;

                rotateButton.Clicked += (sender, ex) =>
                {
                    cropImageView.RotateImage(90);
                };
                stackLayout.Children.Add(rotateButton);

                var finishButton = new Button {
                    Text = "Finished"
                };
                finishButton.CornerRadius = 50;

                Bitmap decoded = null;
                finishButton.Clicked += (sender, ex) =>
                {
                    finishButton.IsEnabled = false;
                    rotateButton.IsVisible = false;
                    finishButton.Text      = "Please Wait...";
                    Bitmap cropped = cropImageView.CroppedImage;

                    using (MemoryStream memory = new MemoryStream())
                    {
                        cropped.Compress(Bitmap.CompressFormat.Png, 100, memory);
                        memory.Position = 0;
                        decoded         = BitmapFactory.DecodeStream(memory);
                        memory.Flush();
                    }



                    WallpaperSet wallpaperSet = new WallpaperSet();
                    bool         val          = wallpaperSet.GetWallpaperBysystem(decoded);



                    page.DidCrop = true;
                    page.Navigation.PopModalAsync();
                };

                stackLayout.Children.Add(finishButton);
                page.Content = stackLayout;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);
            var page = Element as CropView;

            if (page != null)
            {
                #region Crop Image View.
                var cropImageView = new CropImageView(Context);
                cropImageView.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                Bitmap bitmp = BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length);
                cropImageView.SetImageBitmap(bitmp);
                cropImageView.RotateImage(90);
                var imageContent = new ContentView
                {
                    HeightRequest     = 500,
                    WidthRequest      = 600,
                    Content           = cropImageView.ToView(),
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };
                //var scrollView = new ScrollView { Content = cropImageView.ToView() };
                var stackLayout = new StackLayout {
                    Children = { imageContent }, Spacing = 10
                };
                #endregion

                #region Title & Sub Title.
                Label labelTitle = new Label()
                {
                    Text              = "Crop Image",
                    FontSize          = 25,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    TextColor         = Xamarin.Forms.Color.White
                };

                string text = Helper.Helper.SelectedIdentificatorText;
                if (text == "ID")
                {
                    text = "ID Card";
                }

                Label labelSubTitle = new Label()
                {
                    Text     = $"Use the marker to mark the area around your card. So that we only see your {text}.",
                    FontSize = 20,
                    HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    TextColor = Xamarin.Forms.Color.White
                };

                var titleSubTitleLayout = new StackLayout()
                {
                    Children        = { labelTitle, labelSubTitle },
                    Spacing         = 10,
                    VerticalOptions = LayoutOptions.EndAndExpand,
                    Padding         = new Thickness(10, 10, 10, 20)
                };
                stackLayout.Children.Add(titleSubTitleLayout);
                #endregion

                #region Bottom buttons bar.
                var stackLayoutButtons = new StackLayout
                {
                    Orientation       = StackOrientation.Horizontal,
                    HeightRequest     = 50,
                    Spacing           = 40, Margin = new Thickness(0, 0, 0, 20),
                    VerticalOptions   = LayoutOptions.EndAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                };
                var closeButton = new ImageButton
                {
                    Source            = "iconClose.png",
                    Padding           = new Thickness(15),
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    BackgroundColor   = Xamarin.Forms.Color.Transparent
                };
                closeButton.Clicked += (sender, ex) =>
                {
                    page.Navigation.PopModalAsync();
                };
                stackLayoutButtons.Children.Add(closeButton);

                var rotateButton = new ImageButton
                {
                    Source            = "iconRotateToRight.png",
                    Padding           = new Thickness(12),
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    BackgroundColor   = Xamarin.Forms.Color.Transparent
                };

                rotateButton.Clicked += (sender, ex) =>
                {
                    cropImageView.RotateImage(90);
                };
                stackLayoutButtons.Children.Add(rotateButton);

                var finishButton = new ImageButton
                {
                    Source            = "iconChecked.png",
                    Padding           = new Thickness(12),
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    BackgroundColor   = Xamarin.Forms.Color.Transparent
                };
                finishButton.Clicked += (sender, ex) =>
                {
                    Bitmap cropped = cropImageView.CroppedImage;
                    using (MemoryStream memory = new MemoryStream())
                    {
                        cropped.Compress(Bitmap.CompressFormat.Png, 100, memory);
                        App.CroppedImage = memory.ToArray();
                    }
                    page.DidCrop = true;
                    page.Navigation.PopModalAsync();
                };

                stackLayoutButtons.Children.Add(finishButton);
                stackLayout.Children.Add(stackLayoutButtons);
                #endregion

                page.Content = stackLayout;
            }
        }
Example #6
0
 public void OnGetCroppedImageComplete(CropImageView view, Bitmap bitmap, Java.Lang.Exception error)
 {
     handleCropResult(null, bitmap, error);
 }