In my code, I have an image that convert bitmap, change the size and assigned a setDensity. Then I save in sd.
In this example, the final size would be 5x7 inches
This is my code:
private void SaveImage(Bitmap myBitmap) {
int TARGET_DENSITY = 300;
int PHYSICAL_WIDTH_IN_INCH = 5;
int PHYSICAL_HEIGHT_IN_INCH = 7;
Bitmap bmp = Bitmap.createBitmap(PHYSICAL_WIDTH_IN_INCH * TARGET_DENSITY, PHYSICAL_HEIGHT_IN_INCH * TARGET_DENSITY, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.drawBitmap(myBitmap, 0, 0, new Paint());
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/aaa");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
bmp.setDensity(TARGET_DENSITY);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
Log.i("control","Error");
}
}
The original size of the image is w:1024 x h:768px - 300dpi
The final size of the image generated by the app is: w:1500 x h:2100px - 72dpi
If using photoshop to change 72 dpi to 300 dpi, the result is correct (5x7inches), but the picture is output at 72dpi
Is there any way that the image is generated from the app with 300dpi?
I'm looking for information, but without success.
Thanks in advance