I can't found any solution of this issue.
Here is my code:
// Xamarin Android
// Call via Dependency Service
Drawable drawable = TextDrawable.Android.Ui.TextDrawable.TextDrawable.TextDrwableBuilder
.BeginConfig()
.FontSize(70)
.WithBorder(2)
.EndConfig().BuildRound("A", Color.Black);
var img = new ImageView(Application.Context);
img.SetImageDrawable(drawable);
I looked through many answer and I found one but it is not working:
BitmapDrawable bitmapDrawable = (img.Drawable as BitmapDrawable); // this is also null every time
Bitmap bitmap;
if (bitmapDrawable == null)
{
img.BuildDrawingCache();
bitmap = img.DrawingCache; **// Here is Null Every Time**
img.BuildDrawingCache(false);
}
else
{
bitmap = bitmapDrawable.Bitmap;
}
byte[] bitmapData;
using (var stream = new MemoryStream())
{
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
bitmapData = stream.ToArray();
}
When I try this I am getting a null ref exception.
I have a NuGet package that make a Drawable object using text and it is also convert into ImageView. I want to convert that Drawable to byte[] to return to Xamarin.Forms PCL Project.
Can anyone suggest what I should use to achieve text to image in Xamarin Cross Platform Application.