コード例 #1
0
 public Android.Graphics.Drawables.Drawable GetDrawable(string source)
 {
     byte[] data = Convert.FromBase64String(source.Substring(source.IndexOf(",") + 1));
     Bitmap bitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length);
     BitmapDrawable brawable = new BitmapDrawable(bitmap);
     brawable.SetBounds(0, 0, bitmap.Width, bitmap.Height);
     return brawable;
 }
コード例 #2
0
        private BitmapDrawable MakeTagChip (String tagText)
        {
            var Inflater = LayoutInflater.FromContext (Context);
            var tagChipView = (TextView)Inflater.Inflate (Resource.Layout.TagViewChip, this, false);
            tagChipView.Text = tagText.ToUpper ();
            int spec = MeasureSpec.MakeMeasureSpec (0, MeasureSpecMode.Unspecified);
            tagChipView.Measure (spec, spec);
            tagChipView.Layout (0, 0, tagChipView.MeasuredWidth, tagChipView.MeasuredHeight);

            var b = Bitmap.CreateBitmap (tagChipView.Width, tagChipView.Height, Bitmap.Config.Argb8888);

            var canvas = new Canvas (b);
            canvas.Translate (-tagChipView.ScrollX, -tagChipView.ScrollY);
            tagChipView.Draw (canvas);
            tagChipView.DrawingCacheEnabled = true;

            var cacheBmp = tagChipView.DrawingCache;
            var viewBmp = cacheBmp.Copy (Bitmap.Config.Argb8888, true);
            tagChipView.DestroyDrawingCache ();
            var bmpDrawable = new BitmapDrawable (Resources, viewBmp);
            bmpDrawable.SetBounds (0, 0, bmpDrawable.IntrinsicWidth, bmpDrawable.IntrinsicHeight);
            return bmpDrawable;
        }