[mono-android] taking a pic
efontana
eric at fontanas.net
Wed Jan 25 18:59:31 UTC 2012
This works for me; (one for Gallery one for Camera)
private void pickFromGallery()
{
Intent i = new Intent(Intent.ActionGetContent);
i.SetType("image/*");
_activity.StartActivityForResult(i, PICK_FROM_FILE);
}
private void pickFromCamera()
{
Intent intent = new
Intent(Android.Provider.MediaStore.ActionImageCapture);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput,
_activity._photoURI);
intent.PutExtra("outputFormat",
Bitmap.CompressFormat.Jpeg.ToString());
intent.PutExtra("return-data", true);
_activity.StartActivityForResult(intent, PICK_FROM_CAMERA);
}
if (resultCode == Result.Ok)
{
switch (requestCode)
{
case PICK_FROM_CAMERA:
cropPicture(data);
break;
case PICK_FROM_FILE:
_photoURI = Android.Net.Uri.Parse(data.ToURI());
Console.WriteLine("Chose: {0}", _photoURI.Path);
if (!string.IsNullOrEmpty(_photoURI.Path))
cropPicture(data);
else
Toast.MakeText(this, "Cannot use this image",
ToastLength.Short).Show();
break;
case CROP_FROM_CAMERA:
Bundle extras = data.Extras;
Bitmap photo = extras.GetParcelable("data") as Bitmap;
picture.SetImageBitmap(photo);
string croppedImage =
System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath,
"pmc_profile.jpg");
FileStream fs = new FileStream(croppedImage, FileMode.Create);
photo.Compress(Bitmap.CompressFormat.Jpeg, 100, fs);
fs.Close();
FileInfo fi = new FileInfo(croppedImage);
Console.WriteLine("Image Width: {0}, Height: {1}, Density: {2},
Path: {3}, Size: {4}",
photo.Width, photo.Height, photo.Density, fi.FullName,
fi.Length);
uploadPicture(croppedImage);
break;
}
-----
iPhone and Android Developer
www.ericfontana.com
--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/taking-a-pic-tp5158900p5431018.html
Sent from the Mono for Android mailing list archive at Nabble.com.
More information about the Monodroid
mailing list