how can I save a bitmap image to an SD card, losing its original size or quality, I currently use 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 Found"); } }
code>
Found a solution
After the link provided by KPBird, I found that the problem was how the camera activity returned the bitmap object.
To save memory, camera activity returns a scaled image of the captured photo, so the solution has never used this scaled image!
Just add additional camera features by specifying the url where you want to save the image and voilaa !, the captured photo is saved where you want, 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!
source share