I'm currently making an android photography app. In my upload fragment i have a camera intent and a gallery intent, however when i display the image to the image view, the quality of the image lowers. here is my code:
public void CameraIntent(){
cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory(),
"file"+String.valueOf(System.currentTimeMillis())+".jpg");
uri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT , uri);
cameraIntent.putExtra("return-data",true);
startActivityForResult(cameraIntent,0);
}
public void GalleryIntent(){
galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(galleryIntent,"Select Image from Gallery"),2);
}
public void cropImage(){
try{
CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(uri,"image/*");
CropIntent.putExtra("crop","true");
CropIntent.putExtra("outputX",180);
CropIntent.putExtra("outputY",180);
CropIntent.putExtra("aspectX",3);
CropIntent.putExtra("aspectY",3);
CropIntent.putExtra("scaleUpIfNeeded",true);
CropIntent.putExtra("return-data",true);
startActivityForResult(CropIntent,1);
}
catch (ActivityNotFoundException ex)
{
ex.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0 && resultCode == RESULT_OK) {
cropImage();
}
else if(requestCode == 2)
{
if(data != null)
{
uri = data.getData();
cropImage();
}
}
else if (requestCode == 1 && resultCode == RESULT_OK)
{
if(data != null)
{
bundle = data.getExtras();
UriF = data.getData();
bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
seePreview.setEnabled(true);
submitUpload.setEnabled(true);
seePreview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
titleS = title.getText().toString();
descriptionS = description.getText().toString();
openPreview(titleS , descriptionS , bitmap, UriF);
}
});
submitUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
submit(bitmap);
}
});
}
}
I observed a significant loss of quality. here is the actual photo: Actual photo
Here is what it looked like when i put it in the imageview Photo after putting to the image view
there is a significant change in the quality. i tried using the URI, however, UriF = data.getdata() returns null.