Esempio n. 1
0
        private void NewElement_OnDrawBitmap(object sender, EventArgs e)
        {
            var calendarView = sender as ActivityCalendarView;

            if (this.ViewGroup is null || calendarView is null)
            {
                return;
            }

            // If we are not in readonly, we dont generate image.
            if (calendarView.IsInputEnabled)
            {
                return;
            }

            //get the subview
            global::Android.Views.View subView = ViewGroup.GetChildAt(0);
            int width  = ViewGroup.Width;
            int height = ViewGroup.Height;

            //create and draw the bitmap
            Bitmap b = Bitmap.CreateBitmap(800, 800, Bitmap.Config.Argb8888);
            Canvas c = new Canvas(b);

            ViewGroup.Draw(c);

            //save the bitmap to file
            var bytes  = SaveBitmapToBytes(b);
            var base64 = Convert.ToBase64String(bytes);

            calendarView.SetImage(bytes);
        }
        private void NewElement_OnDrawBitmap(object sender, EventArgs e)
        {
            try
            {
                if (this.ViewGroup != null)
                {
                    var element = sender as BarcodeView;

                    //get the subview
                    Android.Views.View subView = ViewGroup.GetChildAt(0);
                    int width  = subView.Width;
                    int height = subView.Height;

                    //create and draw the bitmap
                    Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                    Canvas c = new Canvas(b);
                    ViewGroup.Draw(c);

                    byte[] bitmapData = null;
                    using (var stream = new MemoryStream())
                    {
                        b.Compress(Bitmap.CompressFormat.Png, 0, stream);
                        bitmapData = stream.ToArray();
                    }

                    element.BarcodeUrl = Convert.ToBase64String(bitmapData);
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 3
0
        private Bitmap ConvertViewToBitMap(ViewGroup view)
        {
            Bitmap bitmap = Bitmap.CreateBitmap(1000, 1600, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(bitmap);

            canvas.DrawColor(Color.White);
            view.Draw(canvas);
            return(bitmap);
        }
Esempio n. 4
0
        private void SavePanelAsPNG(ChartViewRenderer chartView, String fileName)
        {
            if (chartView.ViewGroup != null)
            {
                //get the subview
                Android.Views.View subView = ViewGroup.GetChildAt(0);
                int width  = subView.Width;
                int height = subView.Height;

                //create and draw the bitmap
                Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                Canvas c = new Canvas(b);
                ViewGroup.Draw(c);

                //save the bitmap to file
                SaveBitmapToFile(b, fileName);
            }
        }
Esempio n. 5
0
        private void NewElement_OnDrawBitmap(object sender, EventArgs e)
        {
            if (this.ViewGroup != null)
            {
                //get the subview
                Android.Views.View subView = ViewGroup.GetChildAt(0);
                int width  = subView.Width;
                int height = subView.Height;

                //create and draw the bitmap
                Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                Canvas c = new Canvas(b);
                ViewGroup.Draw(c);

                //save the bitmap to file
                SaveBitmapToFile(b);
            }
        }
Esempio n. 6
0
        public Bitmap MakeIcon()
        {
            int measureSpec = View.MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);

            _container.Measure(measureSpec, measureSpec);

            int measuredWidth  = _textView.MeasuredWidth;
            int measuredHeight = _textView.MeasuredHeight;

            _container.Layout(0, 0, measuredWidth, measuredHeight);

            var bubbleDrawable = _context.Resources.GetDrawable(Resource.Drawable.bubble);

            bubbleDrawable.SetBounds(0, 0, measuredWidth, measuredHeight);

            var bitmap = Bitmap.CreateBitmap(measuredWidth, measuredHeight, Bitmap.Config.Argb8888);
            var canvas = new Canvas(bitmap);

            bubbleDrawable.Draw(canvas);
            _container.Draw(canvas);

            return(bitmap);
        }