Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Convert Image to Base64 string

$
0
0

I already did the conversion, but i set the image as static, I don't know how to make it dynamic like, I'll search in my gallery or take some pictures.

Here is my conversion:

Bitmap mBit = BitmapFactory.DecodeResource(Resources, Resource.Drawable.user);
MemoryStream stream = new MemoryStream();
mBit.Compress(Bitmap.CompressFormat.Png, 0, stream);
byte[] ba = stream.ToArray();
string bal = Convert.ToBase64String(ba, Base64FormattingOptions.None);
resultTxt.Text = bal.ToString();

**Here is how I take a picture:
**
private void ClickMeh_Click(object sender, EventArgs e)
{
Intent pfp = new Intent(MediaStore.ActionImageCapture);
StartActivityForResult(pfp, 0);
}

Here is how I display the picture I take in the Image Button:

base.OnActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.Extras.Get("data");
clickMeh.SetImageBitmap(bitmap);

**My Question is:

How to combine all of those?**

Image - Base64string converting is still not clear on me. I just search things up and combine it, that's why i convert it. But the data is static, what I want to convert is the image I took from the camera of from the gallery.

Thanks in advance :)


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>