Reputation: 2656
Using Android's gallery app to select a photo to upload with httppost later. The photo gets uploaded but it's very low quality and size. I have been reading about setting the Bitmap.CompressFormat.PNG
will make it lossless but it's taking the photo from 2000x1500
to 250x187
.
Is it possible that I'm getting the thumbnail and not the actual image? I'm using Photos from Google.
Code
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) {
super.onActivityResult( requestCode, resultCode, data );
if ( resultCode == getActivity().RESULT_OK ) {
selectedImage = Uri.parse( data.getDataString() );
try {
final Bitmap v = DecodeUriImage.Decode( selectedImage, getActivity() );
ByteArrayOutputStream bao = new ByteArrayOutputStream();
v.compress( Bitmap.CompressFormat.PNG, 100, bao );
byte[] byte_arr = bao.toByteArray();
// Add image to array
images.set( selectedImageIndex, Base64.encodeToString( byte_arr, Base64.DEFAULT ) );
} catch ( FileNotFoundException e ) {
e.printStackTrace();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
Result
Upvotes: 0
Views: 74
Reputation: 11214
There is no reason to put the selected image in a Bitmap for later use. Moreover you did not show what all is happening in DecodeUriImage.Decode( selectedImage, getActivity() );
. Maybe it's quality is changed there. Instead realise you have a media path in selectedImage
which you can convert to a real path to the filesystem. Save that path for later use.
If you use it later than just load the file in a byte array and encode base64. Do not use Bitmapfactory.
Upvotes: 0
Reputation: 49
The Bitmap.CompressFormat.PNG will compress the image but It depends on what kink of format you have used on the non-compressed image. You should use a vectorial image to get the best results because on the "compressing transfer" the immage loses the quality both in getting the image bigger on not.
Upvotes: 1