I am working on a camera feature in my application. I am capturing an image and passing it to another activity. The problem that I'm facing is when I display the image in another activity it loses its original result (gets pixilated) for some reason. This is how I'm doing it:
private void takePhotoFromCamera() {
if(ActivityCompat.checkSelfPermission(EnterDataView.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}else {
String[] permissionRequest = {Manifest.permission.CAMERA};
requestPermissions(permissionRequest, 8675309);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK || resultCode != RESULT_CANCELED){
if(requestCode == CAMERA_REQUEST){
Bitmap mphoto = (Bitmap) data.getExtras().get("data");
Intent passPhoto = new Intent(this, Photo.class);
passPhoto.putExtra("byteArray",mphoto);
passPhoto.putExtra("Caller", getIntent().getComponent().getClassName());
startActivity(passPhoto);
}
}
}
Getting the image in other activity like this:
if(getIntent().hasExtra("byteArray")) {
//ImageView _imv= new ImageView(this);
/*Bitmap _bitmap = BitmapFactory.decodeByteArray(
getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);*/
Intent intent_camera = getIntent();
Bitmap camera_img_bitmap = (Bitmap) intent_camera
.getParcelableExtra("byteArray");
//_imv.setImageBitmap(_bitmap);
View view = mInflater.inflate(R.layout.gallery_item, mGallery, false);
ImageView img = (ImageView) view
.findViewById(R.id.id_index_gallery_item_image);
//String uri = getPhotos.getString(getPhotos.getColumnIndex(("uri")));
//Uri mUri = Uri.parse(uri);
//img.setImageURI(mUri);
//byte[] blob = getPhotos.getBlob(getPhotos.getColumnIndex("image"));
//Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length);
//bmpImage.add(bmp);
img.setImageBitmap(camera_img_bitmap);
mGallery.addView(view);
}
My XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/id_index_gallery_item_image"
android:layout_width="@dimen/_300sdp"
android:layout_height="@dimen/_300sdp"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginTop="@dimen/_50sdp"
android:scaleType="centerCrop" />
</RelativeLayout>
What Am I doing wrong?
See Question&Answers more detail:os