# How do I get the image resolution and DPI of a PDF image?

Q: We are using Current Transform Matrix to calculate resolution of
images inside PDF files.

double xRes = width * 72 / ctm.m_a;
double yRes = height * 72 / ctm.m_d;

(as described in the following FAQ - http://www.pdftron.com/net/faq.html#img_01)

Some images have the ctm.m_a and ctm.m_d values zero. In that case,
the above equations give resolution value inifinity. Is there any
other way to retrieve the image resolution.
------
A: It is most likely that your image is rotated (i.e. the CTM has a
rotation component). To obtain the scaling component from a Matrix2D
and compute the resolution of embedded image you could use the
following pseudocode:

// Get the average scaling (by X and Y) from a given Matrix.
double MatrixScale(pdftron.Common.Matrix2D m) {
double x = 0.707106781 * m.getA() + 0.707106781 * m.getB();
double y = 0.707106781 * m.getC() + 0.707106781 * m.getD();
return Math.Sqrt(x*x + y*y);
}

...

double sc = MatrixScale(ctm)
double xRes = width * 72 / sc;
double yRes = height * 72 / sc;