I'm trying to take a picture from device camera or pick it up from the gallery and upload it to the server via the volley everything works fine but the image quality is so bad
private void dispatchTakePictureIntent()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent , CAMERA_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data {
switch (requestCode) {
case CAMERA_REQUEST_CODE:
if ( resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
bitmap = (Bitmap) bundle.get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
}
break;
and getParams method :
byte[] a = convertBitmapToByteArrayUncompressed(bitmap);
params.put("img" , Base64.encodeToString(a , Base64.DEFAULT));
public static byte[] convertBitmapToByteArrayUncompressed(Bitmap bitmap){
ByteBuffer byteBuffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(byteBuffer);
byteBuffer.rewind();
return byteBuffer.array();
}
use
getParcelableExtra()
, instead ofgetExtras()
for small size images.If your images are too large, you have to compress them and send to the other activity. Then you can get compressed bitmap and uncompress it in second activity. Try below code.
1st Activity
2nd Activity
From Naugat Taking picture would be different.
Create a image file fist:
Then dispatch take picture intent
In your onActivity result check for RESULT_OK for a successful capture.
You already got the image path. Now use
mCurrentPhotoPath
to upload process.Also, you need to implement file provider.
In your Manifest add this:
In XML in resource dir and add this:
Now you will get a full-size image from a camera.
Source: https://developer.android.com/training/camera/photobasics.html
You should have to use multipart entity to send image without compression. using multipart entity your image quality also will be maintained. Please follow this to send image using volley