image appears larger than bounding rectangle?

Posted by Kildareflare on Stack Overflow See other posts from Stack Overflow or by Kildareflare
Published on 2010-04-01T13:18:10Z Indexed on 2010/04/01 13:23 UTC
Read the original article Hit count: 302

Filed under:
|
|
|

Hello

I'm implementing a custom print preview control. One of the objects it needs to display is an image which can be several pages high and wide.

I've successfully divided the image into pages and displayed them in the correct order.

Each "page" is drawn within the marginbounds. (That is, each page is sized to be the same as the marginBounds.)

The problem I have is that the image the page represents exceeds the bottom margin.

However if I draw a rectangle with the same dimensions as the image, at the same position as the image, the rectangle matches the marginbounds.

Thus when drawn to the page (in print preview and printed page) the image is larger than a rectangle drawn based on the image dimensions.

I.e. The image is drawn at the same size as e.MarignBounds and is drawn at e.MarginBounds.Location yet exceeds the bottom margin.

How is this?

I've checked resoutions at each step of the process and they are all 96DPI.

    //...
    private List<Image> m_printImages = new List<Image>();
    //...

    private void ImagePrintDocument_PrintPage(object sender, PrintPageEventArgs e)
    {
        PrepareImageForPrinting(e);

        e.Graphics.DrawImage(m_printImages[m_currentPage], new Point(e.MarginBounds.X, e.MarginBounds.Y);

        e.Graphics.DrawRectangle(new Pen(Color.Blue, 1.0F), new Rectangle( new Point(e.MarginBounds.X, e.MarginBounds.Y), new Size(m_printImages[m_currentPage].Width, m_printImages[m_currentPage].Height)));

         //rest of handler
    }

PS Not able to show an image as free image hosting blocked here.

© Stack Overflow or respective owner

Related posts about c#

Related posts about gdi