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; } }
private CropImageView CreateImageView(CropView page) { var cropImageView = new CropImageView(Context) { LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent), }; 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; } }
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 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; } }
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; } }