Change the Resolution of Image in Android

by Wednesday, July 22, 2015 0 comments


After Long search finally your Android-Action find out a solution for changing image resolution ie. dpi/ppi.

Dots per inch (DPI) in this context, refers to the smallest amount of ink that a given printer can print. Put another way, the more dots that a printer (or imagesetter) can apply per inch, the higher the resolution (and therefore quality of image reproduction) an imaging device can reproduce. (Source : designtalkboard)

Pixels per inch (PPI) is often used interchangeably with DPI. PPI is, arguably, where the confusion started from in the first place. PPI a somewhat relative term. Once a photograph is opened in a program such as Adobe Photoshop and displayed on a computer screen, its relation to print paradigm concepts such as per inch are not always helpful. In many cases it is actually more helpful to talk about the total width and height of the digital image in pixels, rather than pixels per inch or dots per inch. (Source : designtalkboard)


Convert image to bitmap using BitmapFactory, then convert to byte[] array(ByteArray) that will store the Bitmap.compress(). From ByteArray



 ByteArrayOutputStream image_barr = new ByteArrayOutputStream();  
 input.compress(Bitmap.CompressFormat.JPEG, 100, image_barr);  
 byte[] image_byte = image_barr.toByteArray();

Based on the JFIF structure we need to edit 13th, 14th, 15th, 16th, and 17th indexes in the byte array. 

13th index             - Density
14th & 15th index        - X resolution
16th & 17th index        - Y resolution
For example if we need to set for 500dpi as the X and Y resolution, then convert decimal to hex value [use this link for conversion binaryhexconverter]

So 500  = 1F4

 image_byte[13] = 00000001;  
 image_byte[14] = 00000001;  
 image_byte[15] = (byte) 244  
 image_byte[16] = 00000001;  
 image_byte[17] = (byte) 244  

As the same for 200 dpi hex value is C8


 image_byte[13] = 00000001;  
 image_byte[15] = (byte) 200  
 image_byte[17] = (byte) 200  

Unknown

Androider

Welcome to Android-Action Blog. I’m a normal guy, who is passionate about Mobile Coding. Here I am writing about Android. Happy learning

0 comments:

Post a Comment