2
I am with the following problem, in my application I take a photo and present her in a imageView
, but when I take the photo she gets the good quality in the gallery imageView
no, if it is a text not even to read, lower I will put the camera code
private void cameraIntent() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
}
private void onCaptureImageResult(Intent data) {
bitmap = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File destination = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
imageView.setImageBitmap(bitmap);
fab.setVisibility(View.VISIBLE);
}
I imagine changing the way you search for the photo solves the problem.
In this same application also has the option to select an image from the gallery and in this option the image comes perfect without change in quality.
private void galleryIntent() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select File"),SELECT_FILE);
}
@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {
if (data == null)
return;
imagemUrl = data.getDataString();
if (imagemUrl != null) {
Glide
.with(this)
.load(imagemUrl)
.into(imageView);
}
fab.setVisibility(View.VISIBLE);
}
did not work, by the test I did it is not recording anything inside the variable outputUri, for that reason it is not loading anything in the imageview, but the image is being recorded in the gallery
– Vitor Hugo
@Vitorhugo You have to assign a value to outputUri as I said, otherwise it will be passed as
null
to the camera. It’s not the camera that decides where to record and fills outputUri with a value, it USES the value you passed in outputUri to record in that location that YOU reported. I usually get a temporary file before. You filled out outputUri and the camera didn’t record anything there? Was it? Or didn’t fill in a value?– Loudenvier
i imagined that this line ( Intent.putExtra(Mediastore.EXTRA_OUTPUT, outputUri); ) recorded a value inside the outputUri, how do I get the Uri of the image that was generated ?
– Vitor Hugo
@Vitorhugo this line only puts the content of the outputUri in the extra of the Intent that goes to the camera. Soon the outputUri already has to be with a path defined by you to where the image will be recorded. It is a way to pass a pro Intent parameter indicating the path of the image you want saved. Tomorrow morning I’ll edit the answer to make it clearer.
– Loudenvier
the only way I know to get the Uri value and through the data Intent that is not working out, I will wait, thanks again, you are the one who is helping me, I imagined that would have more android programmers
– Vitor Hugo
@Vitorhugo is bm simple to solve this! You just need to build the given Uri a path. I will update the code with a routine that creates a temporary file which you can then pass to the insertDb the URI that will be copied, with the ones selected by the gallery... In the future you can even already make the camera record straight in this directory, or if you prefer to play in the local directory later, hare up delete the temporary that create, not to leave a lot of photos in the temporary and in the directory pointed by the BD.
– Loudenvier
Let’s go continue this discussion in chat.
– Vitor Hugo