Hello, I'm saving images to the database. But the resolution is very bad. I'm 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);
}
});
In another section 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.