private DoPrintWithSize ( System.Drawing.Printing.PrintPageEventArgs e ) : |
||
e | System.Drawing.Printing.PrintPageEventArgs | |
Результат |
private static Rectangle GetOrchImageSize(OrchestrationOverviewImage orchestration) { var ov = new OrchViewer(); string text1 = string.Empty; var maxRect = new Rectangle(0, 0, 0, 0); if (orchestration.ViewData != string.Empty) { const int width = 1; const int height = 1; var bmp = new Bitmap(width, height); var memGraphic = Graphics.FromImage(bmp); XLANGView.XsymFile.ReadXsymFromString(ov.Root, orchestration.ViewData, false, ref text1); var ps = new PageSettings(); var marginBounds = new Rectangle(0, 0, width, height); var args = new PrintPageEventArgs( memGraphic, marginBounds, marginBounds, ps); maxRect = ov.DoPrintWithSize(args); ps = null; args = null; memGraphic.Dispose(); bmp.Dispose(); } ov.Dispose(); return(maxRect); }
//TODO: clean up futher public static Bitmap GetOrchestationImage(OrchestrationOverviewImage orchestrationImage, BtsOrchestration orchestration) { var ov = new OrchViewer(); string text1 = string.Empty; if (!string.IsNullOrEmpty(orchestrationImage.ViewData)) { XLANGView.XsymFile.ReadXsymFromString(ov.Root, orchestrationImage.ViewData, false, ref text1); var ps = new PageSettings(); Rectangle maxRect = GetOrchImageSize(orchestrationImage); const int maxWidth = 6000; const int maxHeight = 6000; int w = maxRect.Width, h = maxRect.Height; float scaleX = 1, scaleY = 1; if (w > maxWidth) { scaleX = maxWidth / (float)w; scaleY = scaleX; w = maxWidth; h = (int)Math.Floor(h * scaleY); } if (h > maxHeight) { scaleY *= maxWidth / (float)h; scaleX *= scaleY; h = maxHeight; w = (int)Math.Floor(w * scaleX); } var realBmp = new Bitmap(w, h); var realGraphic = Graphics.FromImage(realBmp); realGraphic.ScaleTransform(scaleX, scaleY); realGraphic.SmoothingMode = SmoothingMode.AntiAlias; realGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic; var realArgs = new PrintPageEventArgs( realGraphic, maxRect, maxRect, ps); // Set background colour //realGraphic.FillRectangle(new SolidBrush(Color.White), maxRect); realGraphic.Clear(Color.White); // Draw the orch image ov.DoPrintWithSize(realArgs); //bool drawHotspots = false; //try //{ // // Decide whether we need hotspots or not // object drawHotspotsObj = new AppSettingsReader().GetValue("ShowHotSpots", typeof(int)); // if (drawHotspotsObj != null) // { // int tmp = Convert.ToInt32(drawHotspotsObj); // if (tmp == 1) drawHotspots = true; // } //} //catch(Exception ex) //{ // ErrorLogger.Log(TraceEventType.Error, ex.NestedExceptionMessage()); //} GetSelectionAreas(realGraphic, ov.Root, orchestrationImage); ps = null; realArgs = null; ov.Dispose(); realGraphic.Dispose(); return realBmp; } else { const string errorText = "Unable to load image for orchestration"; var f = new Font("Arial", 9, FontStyle.Bold); int fontHeight = (int)f.GetHeight() + 5; int errorWidth = MeasureStringWidth(errorText, f); int nameWidth = MeasureStringWidth(orchestration.FullName, f); int w = Math.Max(errorWidth, nameWidth) + 50; const int h = 100; var titleBrush = new SolidBrush(Color.Black); var bmp = new Bitmap(w, h); var g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(Color.White), 0, 0, w, h); g.DrawString(errorText, f, titleBrush, (bmp.Width / 2) - (errorWidth / 2), 10); g.DrawString(orchestration.FullName, f, titleBrush, (bmp.Width / 2) - (nameWidth / 2), 10 + fontHeight); return bmp; } }
private static Rectangle GetOrchImageSize(OrchestrationOverviewImage orchestration) { var ov = new OrchViewer(); string text1 = string.Empty; var maxRect = new Rectangle(0, 0, 0, 0); if (orchestration.ViewData != string.Empty) { const int width = 1; const int height = 1; var bmp = new Bitmap(width, height); var memGraphic = Graphics.FromImage(bmp); XLANGView.XsymFile.ReadXsymFromString(ov.Root, orchestration.ViewData, false, ref text1); var ps = new PageSettings(); var marginBounds = new Rectangle(0, 0, width, height); var args = new PrintPageEventArgs( memGraphic, marginBounds, marginBounds, ps); maxRect = ov.DoPrintWithSize(args); ps = null; args = null; memGraphic.Dispose(); bmp.Dispose(); } ov.Dispose(); return maxRect; }
//TODO: clean up futher public static Bitmap GetOrchestationImage(OrchestrationOverviewImage orchestrationImage, BtsOrchestration orchestration) { var ov = new OrchViewer(); string text1 = string.Empty; if (!string.IsNullOrEmpty(orchestrationImage.ViewData)) { XLANGView.XsymFile.ReadXsymFromString(ov.Root, orchestrationImage.ViewData, false, ref text1); var ps = new PageSettings(); Rectangle maxRect = GetOrchImageSize(orchestrationImage); const int maxWidth = 6000; const int maxHeight = 6000; int w = maxRect.Width, h = maxRect.Height; float scaleX = 1, scaleY = 1; if (w > maxWidth) { scaleX = maxWidth / (float)w; scaleY = scaleX; w = maxWidth; h = (int)Math.Floor(h * scaleY); } if (h > maxHeight) { scaleY *= maxWidth / (float)h; scaleX *= scaleY; h = maxHeight; w = (int)Math.Floor(w * scaleX); } var realBmp = new Bitmap(w, h); var realGraphic = Graphics.FromImage(realBmp); realGraphic.ScaleTransform(scaleX, scaleY); realGraphic.SmoothingMode = SmoothingMode.AntiAlias; realGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic; var realArgs = new PrintPageEventArgs( realGraphic, maxRect, maxRect, ps); // Set background colour //realGraphic.FillRectangle(new SolidBrush(Color.White), maxRect); realGraphic.Clear(Color.White); // Draw the orch image ov.DoPrintWithSize(realArgs); //bool drawHotspots = false; //try //{ // // Decide whether we need hotspots or not // object drawHotspotsObj = new AppSettingsReader().GetValue("ShowHotSpots", typeof(int)); // if (drawHotspotsObj != null) // { // int tmp = Convert.ToInt32(drawHotspotsObj); // if (tmp == 1) drawHotspots = true; // } //} //catch(Exception ex) //{ // ErrorLogger.Log(TraceEventType.Error, ex.NestedExceptionMessage()); //} GetSelectionAreas(realGraphic, ov.Root, orchestrationImage); ps = null; realArgs = null; ov.Dispose(); realGraphic.Dispose(); return(realBmp); } else { const string errorText = "Unable to load image for orchestration"; var f = new Font("Arial", 9, FontStyle.Bold); int fontHeight = (int)f.GetHeight() + 5; int errorWidth = MeasureStringWidth(errorText, f); int nameWidth = MeasureStringWidth(orchestration.FullName, f); int w = Math.Max(errorWidth, nameWidth) + 50; const int h = 100; var titleBrush = new SolidBrush(Color.Black); var bmp = new Bitmap(w, h); var g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(Color.White), 0, 0, w, h); g.DrawString(errorText, f, titleBrush, (bmp.Width / 2) - (errorWidth / 2), 10); g.DrawString(orchestration.FullName, f, titleBrush, (bmp.Width / 2) - (nameWidth / 2), 10 + fontHeight); return(bmp); } }