Search code examples
androidtesseractdpi

Get image size in pixels from DPI (dot per inch) android


I try to get minimum image size for tesseract, from 300 dpi to pixel, in android. I found this answer tell me how to convert dp to pixel, but seems it isn't what I need, as dp = dip = Density-independent pixel (correct me if I'm wrong). For example, if I have an image with size 1024 x 768 pixels, then how I can get its size base on 300 (dpi) dot per inch?


Solution

  • A bitmap doesn't have an "inherent" density, only a resolution (i.e. x by y pixels).

    An image file may contain information about DPIs, but that's only for mapping to physical dimensions (i.e. for printing). For example, an 800px * 600px image with a resolution of 96dpi will be printed as 8.33in * 6.25in, while the print area will be smaller for a higher resolution.

    Therefore, "pixels to dpi" is not a valid conversion -- it's kind of like converting distance into speed.

    I'm not sure about the requirements for tesseract, but if it receives a bitmap as an input then it will be "processing pixels", so I don't think the 300dpi requirement makes sense -- that's probably a rule of thumb to obtain a good result from scanned text of particular (physical) font size.