So I’ve gotten as far as getting the camera to open, take the picture and then return the camera result as follows:
bt.Click += delegate
{
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
StartActivityForResult(intent, 0);
};
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok && requestCode == 0)
{
string result = data.ToURI();
}
The value of result ends up as “#Intent;action=inline-data;B.bitmap-data=true;end”. I don’t really know where to go from here as far as taking the picture result and being able to turn it over to my web-service that will then save it as an image file on the server.
Edit: The final code for anyone with the same problem
bt.Click += delegate
{
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
StartActivityForResult(intent, 0);
};
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
Bitmap bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data");
using (var stream = new System.IO.MemoryStream())
{
bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 0, stream);
byte[] imageBytes = stream.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
inst.saveImage(base64String);
}
}
[WebMethod]
public void saveImage(string stream)
{
byte[] imageBytes = Convert.FromBase64String(stream);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);
var filepath = "C:\\Temp\\Test.png";
using (Stream file = File.OpenWrite(filepath))
{
ms.CopyTo(file, (int)stream.Length);
}
}
The data you get back includes the bitmap data, as your “result” string shows. You can pull the bitmap out of the Intent and compress it out to a stream by doing something like this:
You can use any type of .NET stream there, so the MemoryStream is just an example.