Printing Images C# Overlapping Wrong

Posted by Alen on Stack Overflow See other posts from Stack Overflow or by Alen
Published on 2012-11-14T10:19:57Z Indexed on 2012/11/14 11:00 UTC
Read the original article Hit count: 148

Filed under:
|
|
|

I have created a program much like Photoshop in the sense that you can place images (picture box) on a control, move them around, delete them, and so on... I have also managed to put together a method to print all the images on the control with no problems. But here is the weird part:

When I click print, the program prints the image which was placed first, on top of the image which came second. On the screen the user can see the image which was placed second, on top of the first placed image (the way it should be) but when I print its opposite?

I have no idea why it does this... I hope I've made my self as clear as possible, any help is appreciated!

 public void printToGraphics(Graphics graphics, Rectangle bounds)
 {
        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        Bitmap bitmap = new Bitmap(newLabel.Width, newLabel.Height);

        newLabel.DrawToBitmap(bitmap, newLabel.DisplayRectangle);

        Rectangle target = new Rectangle(0, 0, bounds.Width, bounds.Height);

        target.Height = bitmap.Height;
        target.Width = bitmap.Width;

        graphics.PageUnit = GraphicsUnit.Display;
        graphics.DrawImage(bitmap,target);   
    }

    void printDoc_PrintPage(object sender, PrintPageEventArgs e)
    {   
       printToGraphics(e.Graphics, e.MarginBounds); 
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms