ShowLoClippingTiff.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.  
  14. '' This sample demonstrates how to find and show pixels with clipped shadows.
  15. '' This sample is identical to ShowLoClippingJpeg but uses a TIFF image
  16. '' rather than a JPEG created from the same source photo.
  17. Public Class ShowLoClippingTiff
  18. Function GenerateImage(
  19. ByVal pixelSize As Size,
  20. ByVal dpi As Single,
  21. ByVal opaque As Boolean,
  22. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  23.  
  24. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
  25. Using bmpSrc = New GcBitmap(Path.Combine("Resources", "ImagesBis", "clivia.tiff"))
  26. '' BitBlt requires the opacity of both images to be the same:
  27. bmpSrc.Opaque = opaque
  28. '' Render source image onto the target bitmap
  29. '' (generally we might want to resize the source image first,
  30. '' but in this case we just know that the source image has
  31. '' the same size as the target, so skip this step):
  32. bmp.BitBlt(bmpSrc, 0, 0)
  33.  
  34. Using g = bmp.CreateGraphics()
  35. For i = 0 To bmp.PixelWidth - 1
  36. For j = 0 To bmp.PixelHeight - 1
  37. '' If all of the colors are 0x00, we change the pixel's color to magenta:
  38. If (bmp(i, j) And &HFFFFFF) = 0 Then
  39. bmp(i, j) = &HFFFF00FFUI
  40. End If
  41. Next
  42. Next
  43. '' Draw the original image in the bottom right corner for reference:
  44. Dim rc = New RectangleF(0, 0, pixelSize.Width / 4, pixelSize.Height / 4)
  45. g.DrawImage(bmpSrc, rc, Nothing, ImageAlign.StretchImage)
  46. g.DrawRectangle(rc, Color.LightGray)
  47. End Using
  48. End Using
  49. Return bmp
  50. End Function
  51. End Class
  52.