I am trying to write a piece of code that stores an image captured by an Android device, stores this image and then displays the image in an ImageView. I found some code on StackOverflow (Low picture/image quality when capture from camera) that had a good reception but I cannot implement this code due to Android saying it cannot resolve symbol 'PICTURE_RESULT'. I am wanting to use this code so that the image can be displayed with better image quality than the lower quality that results when displaying straight from image capture.
Here is how I have implemented the code, which is exactly the same as how it has been described in the post I have linked:
public void launchCamera(View view){
values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your camera");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//use standard intent to capture an image
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//output captureIntent to imageUri
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
//Take a picture and pass results along to onActivityResult
PICTURE_RESULT = 1;
startActivityForResult(captureIntent, PICTURE_RESULT);
}
Here is the code for onActivityResult():
protected void onActivityResult(int requestCode, int resultCode, Intent data){
switch (requestCode) {
if (PICTURE_RESULT == 1)
if (resultCode == Activity.RESULT_OK) {
try {
Bitmap thumbnail = MediaStore.Images.Media.getBitmap(
getContentResolver(), imageUri);
imageView.setImageBitmap(thumbnail);
URI imageurl = getRealPathFromURI(imageUri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
And here is the code for getRealPathFromURI():
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}