ShowLoClippingJpeg.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 ShowLoClippingTiff but uses a JPEG image
  16. '' rather than a TIFF created from the same source photo.
  17. Public Class ShowLoClippingJpeg
  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.jpg"))
  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. Using g = bmp.CreateGraphics()
  34. For i = 0 To bmp.PixelWidth - 1
  35. For j = 0 To bmp.PixelHeight - 1
  36. '' If all of the colors are 0x00, we change the pixel's color to magenta:
  37. If (bmp(i, j) And &HFFFFFF) = 0 Then
  38. bmp(i, j) = &HFFFF00FFUI
  39. End If
  40. Next
  41. Next
  42. '' Draw the original image in the bottom right corner for reference:
  43. Dim rc = New RectangleF(0, 0, pixelSize.Width / 4, pixelSize.Height / 4)
  44. g.DrawImage(bmpSrc, rc, Nothing, ImageAlign.StretchImage)
  45. g.DrawRectangle(rc, Color.LightGray)
  46. End Using
  47. End Using
  48. Return bmp
  49. End Function
  50. End Class
  51.