GcLogoHtml.vb
  1. ''
  2. '' This code is part of Document Solutions for Imaging demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Collections.Generic
  8. Imports System.Linq
  9. Imports GrapeCity.Documents.Drawing
  10. Imports GrapeCity.Documents.Text
  11. Imports GrapeCity.Documents.Imaging
  12. Imports GrapeCity.Documents.Html
  13. Imports GCTEXT = GrapeCity.Documents.Text
  14. Imports GCDRAW = GrapeCity.Documents.Drawing
  15.  
  16. '' This sample uses the same code as in the HelloWorld sample
  17. '' to create an image with the "Hello, World!" text, but in addition
  18. '' adds company logo copied from the MESCIUS home page
  19. '' using DsHtml.
  20. ''
  21. '' Please see notes in comments at the top of HelloWorldHtml
  22. '' sample code for details on adding DsHtml to your projects.
  23. Public Class GcLogoHtml
  24. Function GenerateImage(
  25. ByVal pixelSize As Size,
  26. ByVal dpi As Single,
  27. ByVal opaque As Boolean,
  28. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  29.  
  30. '' MESCIUS home page:
  31. Dim uri = New Uri("https://developer.mescius.com/")
  32. '' The coordinates of the logo on the home page:
  33. Dim logoRc = New RectangleF(5, 5, 350, 80)
  34.  
  35. '' Create the "Hello, World!" image like in the HelloWorld sample:
  36. Dim blue = Color.FromArgb(&HFF2E4884)
  37. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
  38. Using g = bmp.CreateGraphics(blue)
  39. Dim rc = New RectangleF(0, 0, pixelSize.Width, pixelSize.Height)
  40. Dim b = New RadialGradientBrush(Color.White, blue, New PointF(0.5F, 0.5F), True)
  41. g.FillRectangle(rc, b)
  42. Dim tf = New TextFormat With
  43. {
  44. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "timesbd.ttf")),
  45. .FontSize = 64,
  46. .ForeColor = Color.OrangeRed
  47. }
  48. g.DrawString("Hello, World!", tf, rc, TextAlignment.Center, ParagraphAlignment.Center, False)
  49.  
  50. '' Copy and paste the logo from onto the image, scaled x2:
  51. Dim fmt = New HtmlToImageFormat(False, False) With
  52. {
  53. .Clip = logoRc,
  54. .Scale = 2
  55. }
  56. '' Create an instance of GcHtmlBrowser that is used to render HTML:
  57. Using browser = Util.NewHtmlBrowser()
  58. Dim s As SizeF
  59. g.DrawHtml(browser, uri, pixelSize.Width - logoRc.Width * fmt.Scale, 0, fmt, s)
  60. End Using
  61. End Using
  62. Return bmp
  63. End Function
  64. End Class
  65.