public Bitmap getImageViewBitmap(ImageView imageView)
        {
            Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageView.Drawable;
            Android.Graphics.Bitmap bitmap = bd.Bitmap;

            return(bitmap);
        }
示例#2
0
        private void DrawTopImageInPurple()
        {
            titleImageView = (ImageView)FindViewById(Resource.Id.myImageView);
            Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)titleImageView.Drawable;
            titleBitmap = bd.Bitmap;
            var vv11 = ApplyBitmapBrightness(23, titleBitmap);

            titleImageView.SetImageBitmap(vv11);
        }
示例#3
0
            protected override async Task <Bitmap> RunInBackground(params Java.Lang.Void[] @params)
            {
                Android.Graphics.Drawables.BitmapDrawable drawable =
                    (Android.Graphics.Drawables.BitmapDrawable)image.Drawable;
                Bitmap bitmap = drawable.Bitmap;

                url = await MeritMoneyBrain.UploadImage(bitmap);

                return(bitmap);
            }
示例#4
0
        private void UploadToCloud()
        {
            ImageView imageView = FindViewById <ImageView>(Resource.Id.mainImage);

            Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageView.Drawable;
            Android.Graphics.Bitmap bitmap = bd.Bitmap;

            string credPath = "google_api.json";

            Google.Apis.Auth.OAuth2.GoogleCredential credential;

            //load our cert into the credential
            using (var stream = Assets.Open(credPath))
            {
                credential = Google.Apis.Auth.OAuth2.GoogleCredential.FromStream(stream);
            }
            credential = credential.CreateScoped(Google.Apis.Vision.v1.VisionService.Scope.CloudPlatform);
            var client = new Google.Apis.Vision.v1.VisionService(
                new BaseClientService.Initializer()
            {
                ApplicationName       = "cs480firsttest-195221",
                HttpClientInitializer = credential
            }
                );

            // tell google that we want to perform feature analysis
            var request = new AnnotateImageRequest();

            request.Image = new Image();

            //converts our bitmap object into a byte[] to send to google
            using (var stream = new System.IO.MemoryStream())
            {
                bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 0, stream);
                request.Image.Content = System.Convert.ToBase64String(stream.ToArray());
            }

            //say we want google to us label detection
            request.Features = new List <Feature>();
            request.Features.Add(new Feature()
            {
                Type = "LABEL_DETECTION"
            });

            //add to list of items to send to goolge
            var batch = new BatchAnnotateImagesRequest();

            batch.Requests = new List <AnnotateImageRequest>();
            batch.Requests.Add(request);

            //Finally, make the call
            var apiResult = client.Images.Annotate(batch).Execute();

            foreach (var item in apiResult.Responses[0].LabelAnnotations)
            {
                tags.Add(item.Description);
                percentage.Add((float)(item.Score));
            }
            AdjustTextView();

            SwitchState();
        }
示例#5
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            Button upload = FindViewById <Button>(Resource.Id.cloudbutton);

            if (requestCode == 1)
            {
                if (resultCode == Result.Ok)
                {
                    var imageView = FindViewById <ImageView>(Resource.Id.mainImage);

                    imageView.SetImageURI(data.Data);

                    Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageView.Drawable;
                    Android.Graphics.Bitmap bitmap = bd.Bitmap;

                    //Gotta shrink down the bitmaps because they tend to be too big



                    int height = bitmap.Height;
                    int width  = bitmap.Width;

                    ScaleBounds(ref height, ref width);

                    Android.Graphics.Bitmap smallBitmap =
                        Android.Graphics.Bitmap.CreateScaledBitmap(bitmap, width, height, true);

                    imageView.SetImageBitmap(smallBitmap);

                    imageView.Visibility = Android.Views.ViewStates.Visible;
                }
            }
            else if (requestCode == 0)
            {
                if (resultCode == Result.Ok)
                {
                    //send to image gallery
                    Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                    var    contentUri      = Android.Net.Uri.FromFile(_file);
                    mediaScanIntent.SetData(contentUri);
                    SendBroadcast(mediaScanIntent);

                    // Display in ImageView. We will resize the bitmap to fit the display.
                    // Loading the full sized image will consume too much memory
                    // and cause the application to crash.
                    ImageView imageView = FindViewById <ImageView>(Resource.Id.mainImage);
                    int       height    = Resources.DisplayMetrics.HeightPixels;
                    int       width     = imageView.Height;

                    //load picture from file
                    Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height);


                    if (bitmap != null)
                    {
                        imageView.SetImageBitmap(bitmap);
                        imageView.Visibility = Android.Views.ViewStates.Visible;
                        bitmap = null;
                    }

                    // Dispose of the Java side bitmap.
                    System.GC.Collect();
                }
            }
            upload.Visibility = Android.Views.ViewStates.Visible;
        }
示例#6
0
        /// <summary>
        /// Element Changed
        /// </summary>
        /// <param name="e"></param>
        protected override void OnElementChanged(ElementChangedEventArgs <ActionButton> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || this.Element == null)
            {
                return;
            }

            if (e.OldElement != null)
            {
                e.OldElement.PropertyChanged -= HandlePropertyChanged;
            }

            if (this.Element != null)
            {
                this.Element.PropertyChanged += HandlePropertyChanged;
            }

            Element.Show   = Show;
            Element.Hide   = Hide;
            Element.Margin = MARGIN;

            if (Element.Color != Color.Transparent)
            {
                Element.Content.Color = Element.Color;
            }

            SetFabSize(Element.Size);

            fab.BackgroundTintList = ColorStateList.ValueOf(Element.ButtonColor.ToAndroid());
            fab.RippleColor        = Element.ColorRipple.ToAndroid();
            fab.Click += Fab_Click;

            var frameLayout = new FrameLayout(Context);

            frameLayout.RemoveAllViews();
            var layout = new LinearLayout(Context);

            layout.Orientation = Android.Widget.Orientation.Horizontal;
            if (!string.IsNullOrWhiteSpace(Element.Tooltip))
            {
                var view = new TextView(Context);
                view.Text = Element.Tooltip;
                view.SetTextColor(Color.White.ToAndroid());
                view.SetBackgroundColor(Color.Black.MultiplyAlpha(0.5).ToAndroid());
                view.LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent)
                {
                    Gravity = GravityFlags.CenterVertical | GravityFlags.CenterHorizontal,
                };
                view.SetPadding(10, 5, 10, 5);
                layout.AddView(view);
            }
            layout.AddView(fab);
            layout.Measure(AT_MOST, AT_MOST);
            frameLayout.AddView(layout);

            if (Element.Content != null)
            {
                var content = Platform.CreateRendererWithContext(Element.Content, Context).View;

                if (content is IConvertable bitmapContent)
                {
                    bitmapContent.SetSize(Element.Size);
                    var bmp      = bitmapContent.ToBitmap((int)Element.Width);
                    var drawable = new Android.Graphics.Drawables.BitmapDrawable(Resources, bmp);
                    fab.SetImageDrawable(drawable);
                }
            }
            SetNativeControl(frameLayout);
            //SetBackgroundColor(Color.Fuchsia.MultiplyAlpha(0.2).ToAndroid());
            //Layout(0, 0, fab.MeasuredWidth + MARGIN * 2, fab.MeasuredHeight + MARGIN * 2);
            Layout(0, 0, layout.MeasuredWidth, layout.MeasuredHeight);
        }