I'm trying to save full-size image on database but the app keep saving image smallest than the original that I took with the camera. Here is the onActivityResult
method:
case TAKE_AVATAR_CAMERA_REQUEST_DOCUMENTO:
case TAKE_AVATAR_CAMERA_REQUEST_INFRACCION:
if (resultCode == Activity.RESULT_CANCELED) {
// Avatar camera mode was canceled.
} else if (resultCode == Activity.RESULT_OK) {
// Took a picture, use the downsized camera image provided by
// default
Bitmap cameraPic = (Bitmap) data.getExtras().get("data");
if (cameraPic != null) {
try {
saveAvatar(cameraPic, requestCode);
} catch (Exception e) {
Log.e(DEBUG_TAG, "saveAvatar() with camera image failed.", e);
}
}
}
break;
private void saveAvatar(Bitmap avatar, int pRequestCode) {
String strAvatarFilename = "avatar.jpg";
String sPreferenceFoto = GAME_PREFERENCES_AVATAR;
String sNumeroActa = (new ActaConstatacionRules(this)).getNextNumeroActa();
int _idButton = 0;
switch (pRequestCode) {
case TAKE_AVATAR_CAMERA_REQUEST_LICENCIA:
strAvatarFilename = sNumeroActa + "_licencia.jpg";
sPreferenceFoto = CURRENT_ACTA_FOTO_LICENCIA;
_idButton = R.id.ImageButton_Licencia;
break;
case TAKE_AVATAR_CAMERA_REQUEST_DOCUMENTO:
strAvatarFilename = sNumeroActa + "_documento.jpg";
sPreferenceFoto = CURRENT_ACTA_FOTO_DOCUMENTO;
_idButton = R.id.ImageButton_Documento;
break;
case TAKE_AVATAR_CAMERA_REQUEST_INFRACCION:
strAvatarFilename = sNumeroActa + "_infraccion.jpg";
sPreferenceFoto = CURRENT_ACTA_FOTO_INFRACCION;
_idButton = R.id.ImageButton_Infraccion;
break;
default:
Utilities.ShowToast(this, "Seleccion de Imagen Invalida");
return;
}
File image = null;
try {
File sdCardDirectory = Environment.getExternalStorageDirectory();
image = new File(sdCardDirectory, strAvatarFilename);
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
avatar.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
Log.e(DEBUG_TAG, "Avatar compression and save failed.", e);
}
strAvatarFilename));
if (image == null)
return;
Uri imageUriToSaveCameraImageTo = Uri.fromFile(image);
Editor editor = mCurrenActaSettings.edit();
editor.putString(sPreferenceFoto, imageUriToSaveCameraImageTo.getPath());
editor.commit();
// Update the settings screen
ImageButton avatarButton = (ImageButton) findViewById(_idButton);
String strAvatarUri = mCurrenActaSettings.getString(sPreferenceFoto, RESOURCE_SIN_FOTO);
Uri imageUri = Uri.parse(strAvatarUri);
avatarButton.setImageURI(null); // Workaround for refreshing an
// ImageButton, which tries to cache the
// previous image Uri. Passing null
// effectively resets it.
avatarButton.setImageURI(imageUri);
}
I need to know how to save the (for example) 600 x 600 image size but without losing quality, now its saving 200 x 100 but I don't know why.