Code to call the camera
if (checkSelfPermission(Manifest.permission.CAMERA) ==
PackageManager.PERMISSION_GRANTED) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
imagePickerLauncher.launch(cameraIntent);
}
The code that saves the image
private void saveImage(Bitmap bitmap) {
File imagesFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyApp");
if (!imagesFolder.exists()) {
imagesFolder.mkdirs();
}
String fileName = "MyImage_" + System.currentTimeMillis() + ".jpg";
File image = new File(imagesFolder, fileName);
try {
FileOutputStream fos = new FileOutputStream(image);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = calculateInSampleSize(bitmap.getWidth(), bitmap.getHeight(), 1080, 1920);
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth()/options.inSampleSize, bitmap.getHeight()/options.inSampleSize, true);
if (resizedBitmap != null) {
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
}
fos.close();
MediaScannerConnection.scanFile(this,
new String[] { image.getAbsolutePath() },
null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
The image is stored in the gallery but in very poor quality.
I experimented with different quality values in the compress argument and format but it didn't help
The image I receive has an extension of 187x250