I have this code, it works very well in android studio but not in xamarin bitmap.Compress() has different arguments in xamarin and i am confused how to convert
If you look at the documentation for Bitmap.Compress in Xamarin, you'll see that the last parameter is a Stream
.
The equivalent of ByteArrayOutputStream
in .NET is MemoryStream
, so your code would be:
Bitmap bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.ace1);
MemoryStream stream = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
byte[] ba = stream.ToArray();
string bal = Base64.EncodeToString(ba, Base64.Default);
(You could use Convert.ToBase64String
instead of Base64.EncodeToString
if you wanted, too.)