How can I get the horizontal and vertical resolution of a bitmap?
<p>I am trying to find the bitmap horizontal and vertical resolution (dpi). I need this information to properly clip my bitmap. I already have the width and the height of the bitmap and this is the only missing information. The (wrong) output that I am getting is the clipping is off. Here is my example. It is marked by "(Missing)" in the code where I would need the Bitmap vertical and horizontal resolution.</p>

<pre><code>final Bitmap clippedBmp;
final Rect&lt;Double&gt; clipRectInInches = imageScaleInPixelAndInches.getClipRect();
final Rect&lt;Integer&gt; clipRectInPixel = new Rect&lt;Integer&gt;();

clipRectInPixel.setX     ((int)(clipRectInInches.getX()      * (Missing)));
clipRectInPixel.setY     ((int)(clipRectInInches.getY()      * (Missing)));
clipRectInPixel.setWidth ((int)(clipRectInInches.getWidth()  * (Missing)));
clipRectInPixel.setHeight((int)(clipRectInInches.getHeight() * (Missing)));

ClipRectUtil.normalizeClipRect(clipRectInPixel, orgBmp.getWidth(), orgBmp.getHeight());
clippedBmp = Bitmap.createBitmap(orgBmp,
                                         clipRectInPixel.getX(),
                                         clipRectInPixel.getY(),
                                         clipRectInPixel.getWidth(),
                                         clipRectInPixel.getHeight());
</code></pre>

<p>here is the normalizeClipRect function</p>

<pre><code>public static void normalizeClipRect(Rect&lt;Integer&gt; clipRectInPixel, int imgWidth, int imgHeight)
{
    int clipX      = clipRectInPixel.getX();
    int clipY      = clipRectInPixel.getY();
    int clipWidth  = clipRectInPixel.getWidth();
    int clipHeight = clipRectInPixel.getHeight();

    if ( clipX &lt; 0 )
        clipX = 0;
    if ( clipY &lt; 0 )
        clipY = 0;

    if ( clipX &gt; imgWidth )
        clipX = imgWidth;
    if ( clipY &gt; imgHeight )
        clipY = imgHeight;

    if ( clipX + clipWidth &gt; imgWidth )
        clipWidth = imgWidth - clipX;
    if ( clipY + clipHeight &gt; imgHeight )
        clipHeight = imgHeight - clipY;

    // update in-place
    clipRectInPixel.setX     (clipX);
    clipRectInPixel.setY     (clipY);
    clipRectInPixel.setWidth (clipWidth);
    clipRectInPixel.setHeight(clipHeight);
}
</code></pre>

<p>I thank you in advance. Please let me know if more information is needed.</p>

<p>Thanks again,</p>

<p>Marc</p>
