I want to take a picture and add image to the activity. I was having a weird pixelation and at first i thought that it was something with the blob I used, but it seems like it has to do with the image after capture from camera.
I activate the camera to take a picture
Camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
Then I want to set image at the imageview.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
int width = photo.getWidth();
int height = photo.getHeight();
Toast.makeText(getApplicationContext(),"Width:"+width+" / Height:"+height,Toast.LENGTH_SHORT).show();
Screen.setImageBitmap(photo);
}
}
After I take the image and there is a preview to verify that I want the image the picture gets pixelated and the resolution of the bitmap I get is 150x205 and I don't know what have I done wrong.
I uploaded a small video to see the actual resolution http://youtu.be/s5Cu3QYSDto
In android the default data which you get from camera is low resolution thumbnail image.
So before you call CameraIntent create a file and uri based on that filepath as shown here.
filename = Environment.getExternalStorageDirectory().getPath() + "/folder/testfile.jpg";
imageUri = Uri.fromFile(new File(filename));
// start default camera
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
imageUri);
startActivityForResult (cameraIntent, CAMERA_REQUEST);
Now, you have the filepath you can use it in onAcityvityResult method as following,you can also get the bitmap from the uri.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
ImageView img = (ImageView) findViewById(R.id.image);
img.setImageURI(imageUri);
}
}