ClearExif.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. '' Clear all Exif tags found in an image.
  18. '' This sample is almost identical to @(ShowExif} but prior to printing
  19. '' Exif tags found in the image it clears all those tags.
  20. '' The expected result is that no tags are found.
  21. Public Class ClearExif
  22. Function GenerateImage(
  23. ByVal pixelSize As Size,
  24. ByVal dpi As Single,
  25. ByVal opaque As Boolean,
  26. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  27.  
  28. Dim pad = 20
  29. Dim side = pixelSize.Width / 3
  30. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
  31. Using g = bmp.CreateGraphics(Color.White)
  32. Using testImage = New GcBitmap(Path.Combine("Resources", "ImagesBis", "fire.jpg"))
  33. '' Remove all existing values from the image's Exif profile:
  34. testImage.ExifProfile.Clear()
  35. '' Note: Individual tags can be removed via testImage.ExifProfile.RemoveValue(tag)
  36.  
  37. '' The remaining code is same as in ShowExif:
  38. Dim tl = g.CreateTextLayout()
  39. tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
  40. tl.DefaultFormat.FontSize = 11
  41. tl.DefaultTabStops = 160
  42. tl.MarginTop = pad
  43. tl.MarginBottom = pad
  44. tl.MarginLeft = pad * 2 + side
  45. tl.MarginRight = pad
  46. tl.MaxWidth = pixelSize.Width
  47. AppendExifData(tl, testImage.ExifProfile)
  48. g.DrawImage(testImage, New RectangleF(pad, pad, side, side), Nothing, ImageAlign.ScaleImage)
  49. If tl.Lines.Count = 0 Then
  50. tl.AppendLine("No EXIF tags found.")
  51. End If
  52. g.DrawTextLayout(tl, PointF.Empty)
  53. End Using
  54. End Using
  55. Return bmp
  56. End Function
  57.  
  58. Private Sub AppendExifData(ByVal tl As TextLayout, ByVal ep As ExifProfile)
  59. Append(tl, ep, ExifTag.Make, ep.Make)
  60. Append(tl, ep, ExifTag.Model, ep.Model)
  61. Append(tl, ep, ExifTag.XResolution, ep.XResolution?.ToString())
  62. Append(tl, ep, ExifTag.YResolution, ep.YResolution?.ToString())
  63. Append(tl, ep, ExifTag.ResolutionUnit, ep.ResolutionUnit.ToString())
  64. Append(tl, ep, ExifTag.Software, ep.Software)
  65. Append(tl, ep, ExifTag.DateTime, ep.DateTimeRaw)
  66. Append(tl, ep, ExifTag.Artist, ep.Artist)
  67. Append(tl, ep, ExifTag.Copyright, ep.Copyright)
  68. Append(tl, ep, ExifTag.ExposureTime, ep.ExposureTime?.ToString())
  69. Append(tl, ep, ExifTag.FNumber, ep.FNumber?.ToString())
  70. Append(tl, ep, ExifTag.ExposureProgram, ep.ExposureProgram.ToString())
  71. Append(tl, ep, ExifTag.PhotographicSensitivity, ep.PhotographicSensitivity?.ToString())
  72. Append(tl, ep, ExifTag.ExifVersion, ep.ExifVersion)
  73. Append(tl, ep, ExifTag.DateTimeOriginal, ep.DateTimeOriginalRaw)
  74. Append(tl, ep, ExifTag.DateTimeDigitized, ep.DateTimeDigitizedRaw)
  75. Append(tl, ep, ExifTag.ShutterSpeedValue, ep.ShutterSpeedValue?.ToString())
  76. Append(tl, ep, ExifTag.ApertureValue, ep.ApertureValue?.ToString())
  77. Append(tl, ep, ExifTag.ExposureBiasValue, ep.ExposureBiasValue?.ToString())
  78. Append(tl, ep, ExifTag.MaxApertureValue, ep.MaxApertureValue?.ToString())
  79. Append(tl, ep, ExifTag.MeteringMode, ep.MeteringMode.ToString())
  80. Append(tl, ep, ExifTag.LightSource, ep.LightSource.ToString())
  81. Append(tl, ep, ExifTag.Flash, ep.Flash.ToString())
  82. Append(tl, ep, ExifTag.FocalLength, ep.FocalLength?.ToString())
  83. '' First 8 symbols in UserComment specify encoding:
  84. Append(tl, ep, ExifTag.UserComment, ep.UserComment?.Substring(8))
  85. Append(tl, ep, ExifTag.SubsecTimeOriginal, ep.SubsecTimeOriginal?.ToString())
  86. Append(tl, ep, ExifTag.SubsecTimeDigitized, ep.SubsecTimeDigitized?.ToString())
  87. Append(tl, ep, ExifTag.ColorSpace, ep.ColorSpace.ToString())
  88. Append(tl, ep, ExifTag.SensingMethod, ep.SensingMethod.ToString())
  89. Append(tl, ep, ExifTag.FileSource, ep.FileSource.ToString())
  90. Append(tl, ep, ExifTag.SceneType, ep.SceneType?.ToString())
  91. Append(tl, ep, ExifTag.CFAPattern, ep(ExifTag.CFAPattern)?.ToString())
  92. Append(tl, ep, ExifTag.CustomRendered, ep.CustomRendered.ToString())
  93. Append(tl, ep, ExifTag.ExposureMode, ep.ExposureMode.ToString())
  94. Append(tl, ep, ExifTag.WhiteBalance, ep.WhiteBalance.ToString())
  95. Append(tl, ep, ExifTag.DigitalZoomRatio, ep.DigitalZoomRatio?.ToString())
  96. Append(tl, ep, ExifTag.FocalLengthIn35mmFilm, ep.FocalLengthIn35mmFilm?.ToString())
  97. Append(tl, ep, ExifTag.SceneCaptureType, ep.SceneCaptureType.ToString())
  98. Append(tl, ep, ExifTag.Contrast, ep.Contrast.ToString())
  99. Append(tl, ep, ExifTag.Saturation, ep.Saturation.ToString())
  100. Append(tl, ep, ExifTag.Sharpness, ep.Sharpness.ToString())
  101. Append(tl, ep, ExifTag.SubjectDistanceRange, ep.SubjectDistanceRange.ToString())
  102. Append(tl, ep, ExifTag.BodySerialNumber, ep.BodySerialNumber)
  103. Append(tl, ep, ExifTag.LensSpecification, ep(ExifTag.LensSpecification)?.ToString())
  104. Append(tl, ep, ExifTag.LensModel, ep.LensModel)
  105. End Sub
  106.  
  107. Private Sub Append(ByVal tl As TextLayout, ByVal ep As ExifProfile, ByVal tag As ExifTag, ByVal text As String)
  108. If ep.HasValue(tag) Then
  109. tl.AppendLine(tag.ToString() + vbTab + text)
  110. End If
  111. End Sub
  112. End Class
  113.