GcLogoHtml.cs
  1. //
  2. // This code is part of Document Solutions for Imaging demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Drawing;
  11. using GrapeCity.Documents.Text;
  12. using GrapeCity.Documents.Imaging;
  13. using GrapeCity.Documents.Html;
  14. using GCTEXT = GrapeCity.Documents.Text;
  15. using GCDRAW = GrapeCity.Documents.Drawing;
  16.  
  17. namespace DsImagingWeb.Demos
  18. {
  19. // This sample uses the same code as in the HelloWorld sample
  20. // to create an image with the "Hello, World!" text, but in addition
  21. // adds company logo copied from the MESCIUS home page
  22. // using DsHtml.
  23. //
  24. // Please see notes in comments at the top of HelloWorldHtml
  25. // sample code for details on adding DsHtml to your projects.
  26. public class GcLogoHtml
  27. {
  28. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  29. {
  30. // MESCIUS home page:
  31. var uri = new Uri("https://developer.mescius.com/");
  32. // The coordinates of the logo on the home page:
  33. var logoRc = new RectangleF(5, 5, 350, 80);
  34.  
  35. // Create the "Hello, World!" image like in the HelloWorld sample:
  36. var blue = Color.FromArgb(unchecked((int)0xFF2e4884));
  37. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);
  38. using (var g = bmp.CreateGraphics(blue))
  39. {
  40. var rc = new RectangleF(0, 0, pixelSize.Width, pixelSize.Height);
  41. var b = new RadialGradientBrush(Color.White, blue, new PointF(0.5f, 0.5f), true);
  42. g.FillRectangle(rc, b);
  43. var tf = new TextFormat
  44. {
  45. Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "timesbd.ttf")),
  46. FontSize = 64,
  47. ForeColor = Color.OrangeRed,
  48. };
  49. g.DrawString("Hello, World!", tf, rc, TextAlignment.Center, ParagraphAlignment.Center, false);
  50.  
  51. // Copy and paste the logo from onto the image, scaled x2:
  52. var fmt = new HtmlToImageFormat(false, false)
  53. {
  54. FullPage = false,
  55. MaxWindowWidth = 300,
  56. MaxWindowHeight = 300,
  57. Clip = logoRc,
  58. Scale = 2
  59. };
  60. // Create an instance of GcHtmlBrowser that is used to render HTML:
  61. using var browser = Common.Util.NewHtmlBrowser();
  62.  
  63. // Draw HTML:
  64. g.DrawHtml(browser, uri, pixelSize.Width - logoRc.Width * fmt.Scale, 0, fmt, out SizeF s);
  65. }
  66. return bmp;
  67. }
  68. }
  69. }
  70.