ShowExif.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 System.Numerics
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GrapeCity.Documents.Text
  12. Imports GrapeCity.Documents.Imaging
  13. Imports GrapeCity.Documents.Imaging.Exif
  14. Imports GCTEXT = GrapeCity.Documents.Text
  15. Imports GCDRAW = GrapeCity.Documents.Drawing
  16.  
  17. '' Print the EXIF tags found in an image.
  18. '' See also ClearExif which uses the same code but removes the EXIF tags first.
  19. Public Class ShowExif
  20. Function GenerateImage(
  21. ByVal pixelSize As Size,
  22. ByVal dpi As Single,
  23. ByVal opaque As Boolean,
  24. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  25.  
  26. Dim pad = 20
  27. Dim side = pixelSize.Width / 3
  28. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
  29. Using g = bmp.CreateGraphics(Color.White)
  30. Using testImage = New GcBitmap(Path.Combine("Resources", "ImagesBis", "fire.jpg"))
  31. Dim tl = g.CreateTextLayout()
  32. tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
  33. tl.DefaultFormat.FontSize = 11
  34. tl.DefaultTabStops = 160
  35. tl.MarginTop = pad
  36. tl.MarginBottom = pad
  37. tl.MarginLeft = pad * 2 + side
  38. tl.MarginRight = pad
  39. tl.MaxWidth = pixelSize.Width
  40. AppendExifData(tl, testImage.ExifProfile)
  41. g.DrawImage(testImage, New RectangleF(pad, pad, side, side), Nothing, ImageAlign.ScaleImage)
  42. If tl.Lines.Count = 0 Then
  43. tl.AppendLine("No EXIF tags found.")
  44. End If
  45. g.DrawTextLayout(tl, PointF.Empty)
  46. End Using
  47. End Using
  48. Return bmp
  49. End Function
  50.  
  51. Private Sub AppendExifData(ByVal tl As TextLayout, ByVal ep As ExifProfile)
  52. Append(tl, ep, ExifTag.Make, ep.Make)
  53. Append(tl, ep, ExifTag.Model, ep.Model)
  54. Append(tl, ep, ExifTag.XResolution, ep.XResolution?.ToString())
  55. Append(tl, ep, ExifTag.YResolution, ep.YResolution?.ToString())
  56. Append(tl, ep, ExifTag.ResolutionUnit, ep.ResolutionUnit.ToString())
  57. Append(tl, ep, ExifTag.Software, ep.Software)
  58. Append(tl, ep, ExifTag.DateTime, ep.DateTimeRaw)
  59. Append(tl, ep, ExifTag.Artist, ep.Artist)
  60. Append(tl, ep, ExifTag.Copyright, ep.Copyright)
  61. Append(tl, ep, ExifTag.ExposureTime, ep.ExposureTime?.ToString())
  62. Append(tl, ep, ExifTag.FNumber, ep.FNumber?.ToString())
  63. Append(tl, ep, ExifTag.ExposureProgram, ep.ExposureProgram.ToString())
  64. Append(tl, ep, ExifTag.PhotographicSensitivity, ep.PhotographicSensitivity?.ToString())
  65. Append(tl, ep, ExifTag.ExifVersion, ep.ExifVersion)
  66. Append(tl, ep, ExifTag.DateTimeOriginal, ep.DateTimeOriginalRaw)
  67. Append(tl, ep, ExifTag.DateTimeDigitized, ep.DateTimeDigitizedRaw)
  68. Append(tl, ep, ExifTag.ShutterSpeedValue, ep.ShutterSpeedValue?.ToString())
  69. Append(tl, ep, ExifTag.ApertureValue, ep.ApertureValue?.ToString())
  70. Append(tl, ep, ExifTag.ExposureBiasValue, ep.ExposureBiasValue?.ToString())
  71. Append(tl, ep, ExifTag.MaxApertureValue, ep.MaxApertureValue?.ToString())
  72. Append(tl, ep, ExifTag.MeteringMode, ep.MeteringMode.ToString())
  73. Append(tl, ep, ExifTag.LightSource, ep.LightSource.ToString())
  74. Append(tl, ep, ExifTag.Flash, ep.Flash.ToString())
  75. Append(tl, ep, ExifTag.FocalLength, ep.FocalLength?.ToString())
  76. '' First 8 symbols in UserComment specify encoding:
  77. Append(tl, ep, ExifTag.UserComment, ep.UserComment?.Substring(8))
  78. Append(tl, ep, ExifTag.SubsecTimeOriginal, ep.SubsecTimeOriginal?.ToString())
  79. Append(tl, ep, ExifTag.SubsecTimeDigitized, ep.SubsecTimeDigitized?.ToString())
  80. Append(tl, ep, ExifTag.ColorSpace, ep.ColorSpace.ToString())
  81. Append(tl, ep, ExifTag.SensingMethod, ep.SensingMethod.ToString())
  82. Append(tl, ep, ExifTag.FileSource, ep.FileSource.ToString())
  83. Append(tl, ep, ExifTag.SceneType, ep.SceneType?.ToString())
  84. Append(tl, ep, ExifTag.CFAPattern, ep(ExifTag.CFAPattern)?.ToString())
  85. Append(tl, ep, ExifTag.CustomRendered, ep.CustomRendered.ToString())
  86. Append(tl, ep, ExifTag.ExposureMode, ep.ExposureMode.ToString())
  87. Append(tl, ep, ExifTag.WhiteBalance, ep.WhiteBalance.ToString())
  88. Append(tl, ep, ExifTag.DigitalZoomRatio, ep.DigitalZoomRatio?.ToString())
  89. Append(tl, ep, ExifTag.FocalLengthIn35mmFilm, ep.FocalLengthIn35mmFilm?.ToString())
  90. Append(tl, ep, ExifTag.SceneCaptureType, ep.SceneCaptureType.ToString())
  91. Append(tl, ep, ExifTag.Contrast, ep.Contrast.ToString())
  92. Append(tl, ep, ExifTag.Saturation, ep.Saturation.ToString())
  93. Append(tl, ep, ExifTag.Sharpness, ep.Sharpness.ToString())
  94. Append(tl, ep, ExifTag.SubjectDistanceRange, ep.SubjectDistanceRange.ToString())
  95. Append(tl, ep, ExifTag.BodySerialNumber, ep.BodySerialNumber)
  96. Append(tl, ep, ExifTag.LensSpecification, ep(ExifTag.LensSpecification)?.ToString())
  97. Append(tl, ep, ExifTag.LensModel, ep.LensModel)
  98. End Sub
  99.  
  100. Private Sub Append(ByVal tl As TextLayout, ByVal ep As ExifProfile, ByVal tag As ExifTag, ByVal text As String)
  101. If ep.HasValue(tag) Then
  102. tl.AppendLine(tag.ToString() + vbTab + text)
  103. End If
  104. End Sub
  105. End Class
  106.