image - Android - how to get or set (print) DPI ( dots per inch ) of JPEG file while loading or saving it programmatically? -


itemprop = "text">

I have an app developed on Android version 4.0 and above. (Apps 4.0 versions [Ice Cream Sandwich]) does not support Android versions.

The question is related to different images (printed) DPI (for example, JPEG or PNG) format.

This question is not related to screen dpi or the size of various Android devices. This screen is not related to showing bitmap on device in size.

I am using the following code to load the image file in 'Bitmap'. So I'm harvesting it and saving it in JPEG format with JPG compression in another file. I am able to do this with the following code, but I am unable to load the DPI or I am setting the DPI of the saved image file.

So I have two questions.

1) After loading (print) DPI from JPEG file in 'Bitmap' or how can I get it while loading? 2) When saving the new generated 'bitmap', how can I set the DPI then in the JPEG file?

The code is part of the reference.

  FileInputStream inputstream = new FileInputStream (theSourcePhotoFilePathName); Bitmap bitmap = null; Bitmapregion decoder decoder = faucet; Bitmapfactor Option option = new bitmapfile the option (); Options.inSampleSize = 1; Options.inDensity = 300; // try it but try not to work in {decoder = bitmapRegionDecoder.newInstance (false); Bitmap = decoder.decodeRegion (area, option); / / There is crop of coordination in this area} hold (invalid record exception e) {log d. ("First Activity", "Failed to Recycle Bitmap for Rectification" = Area, E); } Hold (IOException e) {log d. ("First Activity", Failed to decode in "Rect =" area, e); } Finally {if (decoder! = Null) decoder Recycle (); } Inputstream.close (); Inputstream = faucet; FileOutputStream fos = New FileOutputStream (theTargetTempFolderDestFilePath); Bitmap.compress (compressed format.jpg, jpg comresario, fos); Fos.flush (); Fos.close (); Fos = null; I tried to find stackoverflow and other sites by googling, but could not find the appropriate related answer. So I decided to ask it in this forum.  

Your hints and tips are welcome.

Sanjay

Do you discuss the DPI metadata written as part of the JPEG file? I have struggled on it recently, but came up with a solution if you have already solved it, then this answer can help those other people who come in the same problem.

When JPEG is compressed in a bitmap Android, it saves it in the JFIF segment format. Please see the article here (). I have also opened a screenshot of an Android JPEG image in a hex editor so that you can see how it matches.

Enter image details here

edit it To do this, you need to first create a byte [] array that will store bitcaps.com (). This is a part of my code where I do this (input bitmap source).

  BytereonOperputStream uploadsizeabetre = new byteOrout OutputStream (); Input.compress (Bitmap Compress Format. JPEG, 100, Upload ImagesBetaEre); Byte [] Upload ImageData = Upload ImageBitArray To Batere ();  

Depending on the JFIF structure, you must edit the 13th, 14th, 15th, 16th, and 17th index in the byte array. Specifying 13 density type, 14th and 15th x resolutions, and 16th and 17th resolution Y resolution in my case, I changed it into 500dpi in the form of X and Y resolutions in metadata. This has been translated into 0000 0001 1111 0100 which is 1F4 in hex. I then wrote the byte [] in the file, copied it from my computer to my computer and verified that the details were present in view of the image properties.

  uploadImageData [13] = 00000001; UploadImageData [14] = 00000001; Upload Image Data [15] = (Byte) 244 Upload Image Data [16] = 00000001; UploadImageData [17] = (byte) 244 file image = new file (environment .getExternalStoragePublicDirectory (environment. DIRECTORY_DOWNLOADS) .getAbsolutePath () + "/ Meta Images /", imageFileName); FileOutputStream sdCardOutput = New FileOutputStream (Image); SdCardOutput.write (uploadImageData);  Note:  Java uses a signed byte system and you can not enter any binary value above 127 without entering the compiler. I went to input this problem as a byte to F4 input, its solution is to convert your value into decimal and then use one (byte). 

Hope it helps!


Comments