How to save a bitmap that I got from camera, to the sd card without losing it's original size and quality
how can I save a Bitmap Image to the sdcard with loosing it's original size or quality, I am currently using this code, but it always saves the image much smaller than the original size of the image captured by the camera.
private void SaveImage(Bitmap bitmap, String strType) {
File sdImageMainDirectory = new File("/sdcard/");
if (sdImageMainDirectory.exists()) {
FileOutputStream fileOutputStream = null;
Date dt = new Date();
String nameFile = "myImage";
int quality = 100;
try {
String strFullImageName;
strFullImageName = UserID + "_" + nameFile + ".jpg";
fileOutputStream = new FileOutputStream(
sdImageMainDirectory.toString() + "/"
+ strFullImageName);
BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
bitmap.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
UploadImage(bitmap, strFullImageName, strType);
} catch (FileNotFoundException e) {
Utilities.LogError(e);
} catch (IOException e) {
Utilities.LogError(e);
} catch (Exception eee) {
Utilities.LogError(eee);
}
} else {
Utilities.LogError("File not 开发者_如何学PythonFound");
}
}
Found the solution,
After following the link provided by KPBird, I found that the problem was in how the camera activity was returning the bitmap object captured.
To preserver memory, the camera activity returns a scaled image of the captured photo, so the solution was to never use this scaled image!
Just pass an extra to the camera intent, providing the url where you want to save the image and voilaa!, the captured photo is saved where you want it, with the original scale
Code:
private static final int CAMERA_PIC_REQUEST = 1337;
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
imageNameToUpload = "myImage.jpeg";
cameraIntent.putExtra( android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File( imagePathToUpload+imageNameToUpload)));
startActivityForResult(cameraIntent,
CAMERA_PIC_REQUEST);
Thanks KPBird!
Visit following link
How do I save data from Camera to disk using MediaStore on Android?
It may help
精彩评论