How do I find out if the image is flipped/mirrored?

53 views
Skip to first unread message

Support

unread,
Oct 17, 2007, 9:06:11 PM10/17/07
to PDFTron PDFNet SDK
Q:

When I extract a bitmap out of the image element, the dimension of the
image is "landscape", which seems to be incorrect. Am I doing
something wrong or is this the original format of the contained image.

The code I used to extract the image is similar to:

while ( (element = page_reader.Next()) != null ) // Read page
contents
{
elementType = element.GetType();
if ( elementType == Element.Type.e_image || elementType ==
Element.Type.e_inline_image )
{
imageElement = element;
transform = new Matrix2D( element.GetCTM() );
break;
}
}

if ( imageElement != null )
{
if ( transform.m_b != 0 || transform.m_c != 0 )
{
Debug.Assert( false, "Unsupported image transform in
GetSingleRasterImage()" );
return null;
}

Obj o = imageElement.GetXObject();
pdftron.PDF.Image pdfImage = new pdftron.PDF.Image( o );
Bitmap bmp = pdfImage.GetBitmap();

if ( transform.m_a < 0 )
{
bmp.RotateFlip( RotateFlipType.RotateNoneFlipY );
}
if ( transform.m_d < 0 )
{
bmp.RotateFlip( RotateFlipType.RotateNoneFlipX );
}

return bmp;
}

----

A:

The following is the transformation matrix used to draw the image:
609.8824 0 0 -837.551 0 837.551 cm
a---------- b-c-d----------h-v

Since the last parameter (d) is negative and b & c are 0, this
represents scale matrix with Y filp. The image is effectively
mirrored. If the first parameter (i.e. 'a') was negative the image
would be flipped/mirrored horizontally.

Reply all
Reply to author
Forward
0 new messages