In my application I capture photo by android camera and then I want to send it to the server. For this I use Client Socket programming. I convert the capture photo into bytearray(byte[]) and then send it to the server. Every thing work perfactally.
Problem is there I am not able to send original photo to the server. Thumbnail photo is sended by the android mobile phone. But when I capture photo by the camera then original photo is there in Gallery.
How to get this original photo to use in my application?
My Code:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG);
cameraIntent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(cameraIntent, "Select Picture"),
CAMERA_REQUEST);
And in onActivityResult method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
// byte[] a = (byte[]) data.getExtras().getByteArray("data"); // I also use this but not work
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(CompressFormat.JPEG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
}
}
in bitmapdata photo is there but compressed photo not the original. Some of people say that, change quality field of compress(CompressFormat.JPEG, 100, bos); in between 0 to 100 but nothing will happen.
-- >> is there any other way also to get original photo which is captured by the camera
-- >> When The photo is in folder of my computer then I read this photo in the file by giving the path. ex- File file = new File(c:\newphoto\image.jpg); . can I use this code in android to read original photo because I know the name and location of photo. If yes then what is the path to read photo in gallery. Is this work if I give path as: \DCIM\Camera\photoName.jpg.
-- >> Or some change need in my current code and it will work fine?