2
Hello, I am saving images in the database. But the resolution is very bad. I am using the following:
btncamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tirarfoto();
}
});
btngaleria.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galeriaIntent = new Intent(Intent.ACTION_GET_CONTENT);
galeriaIntent.setType("image/*");
startActivityForResult(galeriaIntent, ESCOLHERFOTO);
}
});
Elsewhere I use this:
if (foto != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
foto.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bytearray = stream.toByteArray();
final ParseFile fileimagem = new ParseFile("imagem.jpg", bytearray);
fileimagem.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
salvarDica(fileimagem);
}
}
});
} else {
salvarDica(null);
}
And I also have these methods:
private void tirarfoto() {
Intent abrircamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
if (abrircamera.resolveActivity(getPackageManager()) != null) {
startActivityForResult(abrircamera, TIRARFOTO);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ESCOLHERFOTO && resultCode == RESULT_OK) {
uricaminhodafoto = data.getData();
try {
foto = MediaStore.Images.Media.getBitmap(getContentResolver(), uricaminhodafoto);
foto = Bitmap.createScaledBitmap(foto, 200, 200, false);
} catch (IOException e) {
e.printStackTrace();
}
picture.setImageBitmap(foto);
}
if (requestCode == TIRARFOTO && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
foto = (Bitmap) extras.get("data");
picture.setImageBitmap(foto);
}
}
Part of my setup:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/picture"
android:src="@drawable/picture"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:cropToPadding="false" />
The resolution of the saved image is terrible. Does anyone know how to solve it? Thank you.
In addition to Victor’s answer, if you want you can read this very explanatory post about image resizing (watch out for memory): http://answall.com/questions/82305/qual%C3%A9-a-more-efficient-way-to-resize-bitmaps-no-android
– Ismael