Thanks Willem. I will be trying this out later today and report back.
From: [email protected]
To: [email protected]
Date: Tue, 2 Aug 2011 14:29:38 +0000
Subject: Re: [mono-android] getting a pic from the camera
Hi Wally,
Actually you can do something useful with the intent you’re getting back from
the activity result.
protected override void OnActivityResult(int requestCode, Result resultCode,
Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TakePictureRequestCode && resultCode == Result.Ok)
{
var dataUri = data.ToURI();
var imageView = FindViewById<ImageView>(Resource.Id.selected_picture);
imageView.SetImageURI(Android.Net.Uri.Parse(dataUri));
}
}
This is basically the thing to get a picture back from the camera
J
Met vriendelijke groet,
Willem Meints
Ontwikkelaar PDC
Van: [email protected]
[mailto:[email protected]]
Namens Wally McClure
Verzonden: Tuesday, August 02, 2011 3:58 PM
Aan: [email protected]
Onderwerp: [mono-android] getting a pic from the camera
I'm trying to start the camera application and get an image back. I think I
should be able to get
the image back in the OnActivityResult method. Unfortunately, I am missing
something as I don't seem to get anything back. All of what look to be the
interesting pieces of the data Intent seem to be null. I suspect that the
problems are on my end. I get
the "data" object back. Unfortunately, I don't get a file uri that I can open
as an image. I don't get anything back. Any suggestions on how to get the
image back when I take a picture?
Wally
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Graphics
{
[Activity(Label = "Take Pictures Activity")]
public class takepictures : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
SetContentView(Resource.Layout.takepictures);
Button btnCTP = FindViewById<Button>(Resource.Id.btnCloseTakePics);
btnCTP.Click += new EventHandler(btnCTP_Click_Close);
saveFullImage();
}
void btnCTP_Click_Close(object sender, EventArgs e)
{
this.Finish();
}
private static int TAKE_PICTURE = 1;
private Uri outputFileUri;
private void getThumbailPicture() {
Intent intent = new
Intent(Android.Provider.MediaStore.ActionImageCapture);
StartActivityForResult(intent, TAKE_PICTURE);
}
private void saveFullImage() {
Intent intent = new
Intent(Android.Provider.MediaStore.ActionImageCapture);
string file =
System.IO.Path.Combine(Android.OS.Environment.DirectoryDcim.ToString(),
"test.jpg");
var outputFileUri = Android.Net.Uri.Parse(file);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput,
outputFileUri);
StartActivityForResult(intent, TAKE_PICTURE);
}
protected override void OnActivityResult(int requestCode, Result
resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null)
{
if (data.HasExtra("data"))
{
var thumbnail = data.GetParcelableArrayExtra("data");
// TODO Do something with the thumbnail
}
}
else
{
var outputFileUri =
data.GetParcelableArrayExtra("outputFileuri");
// TODO Do something with the full image stored
// in outputFileUri
}
}
}
}
}
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid