Exemplo n.º 1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.main_action_crop:
                _cropImageView.GetCroppedImageAsync();
                return(true);

            case Resource.Id.main_action_rotate:
                _cropImageView.RotateImage(90);
                return(true);

            default:
                if (item.ItemId == Resource.Id.main_action_flip_horizontally)
                {
                    _cropImageView.FlipImageHorizontally();
                    return(true);
                }
                else if (item.ItemId == Resource.Id.main_action_flip_vertically)
                {
                    _cropImageView.FlipImageVertically();
                    return(true);
                }
                break;
            }
            return(base.OnOptionsItemSelected(item));
        }
Exemplo n.º 2
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);
                Bitmap bitmp = BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length);
                cropImageView.SetImageBitmap(bitmp);

                var grid = new Grid();
                grid.RowDefinitions.Add(new RowDefinition
                {
                    Height = GridLength.Star
                });
                grid.RowDefinitions.Add(new RowDefinition
                {
                    Height = GridLength.Auto
                });
                grid.RowDefinitions.Add(new RowDefinition
                {
                    Height = GridLength.Auto
                });

                var stackLayout = new StackLayout {
                    Children = { cropImageView }
                };

                var rotateButton = new Button {
                    Text = "Rotate"
                };

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

                var finishButton = new Button {
                    Text = "Finished"
                };
                finishButton.Clicked += (sender, ex) =>
                {
                    Bitmap cropped = cropImageView.CroppedImage;
                    using (MemoryStream memory = new MemoryStream())
                    {
                        cropped.Compress(Bitmap.CompressFormat.Png, 100, memory);
                        page.CroppedImage = memory.ToArray();
                    }
                    page.Navigation.PopModalAsync();
                };

                grid.Children.Add(stackLayout, 0, 0);
                grid.Children.Add(rotateButton, 0, 1);
                grid.Children.Add(finishButton, 0, 2);
                page.Content = grid;
            }
        }
Exemplo n.º 3
0
        private static Button CreateRotateButton(CropImageView view, string buttonText)
        {
            var rotateButton = new Button
            {
                Text   = buttonText,
                Style  = Application.Current.Resources["WarnButton"] as Style,
                Margin = ButtonMargin
            };

            rotateButton.Clicked += (sender, ex) => view.RotateImage(90);
            return(rotateButton);
        }
Exemplo n.º 4
0
 public override bool OnOptionsItemSelected(IMenuItem item)
 {
     if (item.ItemId == Resource.Id.main_action_crop)
     {
         mCropImageView.GetCroppedImageAsync();
         return(true);
     }
     else if (item.ItemId == Resource.Id.main_action_rotate)
     {
         mCropImageView.RotateImage(90);
         return(true);
     }
     return(base.OnOptionsItemSelected(item));
 }
        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;
            }
        }
Exemplo n.º 6
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);
                Bitmap bitmp = BitmapFactory.DecodeByteArray(page.Image, 0, page.Image.Length);
                cropImageView.SetImageBitmap(bitmp);

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

                var rotateButton = new Button {
                    Text = "Rotate"
                };

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

                var finishButton = new Button {
                    Text = "Finished"
                };
                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();
                };

                stackLayout.Children.Add(finishButton);
                page.Content = stackLayout;
            }
        }
        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();
            }
        }
Exemplo n.º 8
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;
            }
        }
Exemplo n.º 9
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;
            }
        }
Exemplo n.º 10
0
        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;
            }
        }