02-02-2009 06:06 PM
Pete,
I've been messing with this and trying to get it to work and I haven't been successful yet. What I've found is that you should create a new bitmap file, create the graphics object from that bitmap, then write to the graphics object, rather than writing to the graphics object presented by the printeventargs. However, since this is what you are doing, I'm not sure what you are doing wrong. I tried saving the bitmap after drawing to it, but that provided a GDI+ "generic error".
If I do find a solution, I'll let you know, but since this is more of a .NET issue, the people at the MSDN forums may be of more help (C# forums here: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads/)
If anyone else has suggestions, feel free to post them.
02-03-2009 12:34 PM
Hey Eric,
Well I got everything to print with the code below. My issue now is with the resolution of the x and y axes and this is a Measurement Studio issue, I believe. I set the resolution of my bitmap to 600 dpi (which is also the dpi of the PrintPageEventArgs found in the printing example) and the scatterplot happily adjusts but the axes expand in size even though I set the bounds to match to scattergraph's dimensions. any thoughts?
Bitmap _scatterGraphBmp;
private void GraphToBitmap()
{
_scatterGraphBmp = new Bitmap(1,1, PixelFormat.Format32bppArgb);
_scatterGraphBmp.SetResolution(600, 600);
Graphics gBmp = Graphics.FromImage(_scatterGraphBmp);
gBmp.Dispose();
_scatterGraphBmp.Dispose();
_scatterGraphBmp = new Bitmap(900,650, PixelFormat.Format32bppArgb);
_scatterGraphBmp.SetResolution(600, 600);
gBmp = Graphics.FromImage(_scatterGraphBmp);
Rectangle yBounds = yAxis1.GetBounds();
Rectangle xBounds = xAxis1.GetBounds();
Rectangle plotBounds = new Rectangle(yBounds.Width, xBounds.Height, 899 - yBounds.Width, 649 - xBounds.Height);
// Draw Chart Elements
yBounds = yAxis1.GetBounds(gBmp, plotBounds);
xBounds = xAxis1.GetBounds(gBmp, plotBounds);
xAxis1.Draw(new ComponentDrawArgs(gBmp, xBounds), XAxisPosition.Bottom);
yAxis1.Draw(new ComponentDrawArgs(gBmp, yBounds), YAxisPosition.Left);
scatterGraph1.DrawGridLines(new ComponentDrawArgs(gBmp, plotBounds));
scatterPlot1.Draw(new ComponentDrawArgs(gBmp, plotBounds));
gBmp.DrawRectangle(new Pen(Brushes.Black), plotBounds);
gBmp.Dispose();
}
Thanks,
Pete
02-04-2009 06:12 PM
Hey Pete,
What do you mean that the axes expand in size? Can you post a picture?
Thanks!
02-11-2009 03:35 PM