title: How do I convert a Graphics object to a Bitmap object, inside PrintPage event?
body: <p>This is the high level problem I'm trying to solve...</p>
  
  <p>I have a 3rd party plotting/graphing (IoComp Plot), and I want to embed a <strong>high quality</strong> (at least 600 dpi) bitmap of the Plot control in reports created by another 3rd party report package (Combit List &amp; Label).</p>
  
  <p>This is the approach that seems most promising so far...</p>
  
  <p><strong>---Edit---:</strong> </p>
  
  <p>After trying many other approachs, the only one that I think I can make work is to create a hidden instance of the Plot control, with everything scaled up to printer size  (approx 5 times screen size).  That includes width and height, font sizes, line widths - every visible component of the control.  Yuck!</p>
  
  <p><strong>------</strong></p>
  
  <p>I can get a <strong>Graphics</strong> object of the proper resolution from the plot control's PrintPage event, but converting it to a Bitmap so the report package will be happy is proving to be the major stumbling block.  Several hours of searching has led to other people who asked the same question, but no viable answers.</p>
  
  <p>The only promising lead I've found suggested using one of the Bitmap constructors, which takes a Graphics instance as a parameter.  </p>
  
  <p>However, it's not working for me.  It creates Bitmap, but with no content from the Plot control - it is a pure black image.</p>
  
  <p>Here's my code (edited to show drawing of red line to Graphics object):</p>
  
  <pre><code>void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
  {
          // Draw a red line on the Graphics object. When printed, this
          // line is shown as part of the normal Plot graphics.
          Pen myPen;
          myPen = new Pen(Color.Red);
          e.Graphics.DrawLine(myPen, 0, 0, 200, 200);
          myPen.Dispose();
  
          // Create a bitmap from the Graphics object
          Bitmap bm = new Bitmap(1000, 1000, e.Graphics);
  
          // Save to disk 
          // DOES NOT WORK - CREATES FILE THAT IS PURE BLACK (VIEWED
          // WITH "PAINT" PROGRAM)
          bm.Save(@"C:\Bicw_Dev\Bic.Net\FrontEnd\GraphicsToBmp.bmp", ImageFormat.Bmp);
          bm.Dispose();
  }
  </code></pre>
  
  <p>Can anyone suggest why this doesn't work?  Is this even a valid approach?</p>
  
  <p>Also, please note:</p>
  
  <p>As far as I can determine (and I've spent quite a bit of time looking) <strong>there is no way to get a high resolution, print quality Bitmap from the Plot control directly</strong>!  </p>
  
  <p>I stress this because several others who asked the question got code samples in response that solved the <strong>opposite</strong> problem - converting a Bitmap to a Graphics.  </p>
  
  <p>I need to convert a <strong>Graphics</strong> object to a <strong>Bitmap</strong> object.</p>
  
  <p>And if anyone can suggest an alternate approach that allows me to get a <strong>print quality</strong> image of my plots into my reports, please feel free. (For example, I can get a <strong>low quality</strong> (72 bpi) Bitmap from the Plot control, and have considered trying to stretch it - but I've never seen that approach work well in other applications).</p>
  
  <p>Thanks,</p>
  
  <p>-Tom Bushell</p>
  
  <p>Edit in response to comment:</p>
  
  <p>As an experiment, I added the following: </p>
  
  <pre><code>Pen myPen; 
  myPen = new Pen(Color.Red); 
  e.Graphics.DrawLine(myPen, 0, 0, 200, 200); 
  myPen.Dispose(); 
  </code></pre>
  
  <p>This caused a red line to be drawn over the plot graphics when I printed my plot. But it had no effect on the Bitmap - it's still pure black.</p>