ShowLoClippingTiff.cs
  1. //
  2. // This code is part of Document Solutions for Imaging demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Numerics;
  11. using GrapeCity.Documents.Drawing;
  12. using GrapeCity.Documents.Text;
  13. using GrapeCity.Documents.Imaging;
  14.  
  15. namespace DsImagingWeb.Demos
  16. {
  17. // This sample demonstrates how to find and show pixels with clipped shadows.
  18. // This sample is identical to ShowLoClippingJpeg but uses a TIFF image
  19. // rather than a JPEG created from the same source photo.
  20. public class ShowLoClippingTiff
  21. {
  22. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  23. {
  24. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
  25. using (var bmpSrc = new GcBitmap(Path.Combine("Resources", "ImagesBis", "clivia.tiff")))
  26. {
  27. // BitBlt requires the opacity of both images to be the same:
  28. bmpSrc.Opaque = opaque;
  29. // Render source image onto the target bitmap
  30. // (generally we might want to resize the source image first,
  31. // but in this case we just know that the source image has
  32. // the same size as the target, so skip this step):
  33. bmp.BitBlt(bmpSrc, 0, 0);
  34.  
  35. using (var g = bmp.CreateGraphics())
  36. {
  37. for (int i = 0; i < bmp.PixelWidth; ++i)
  38. for (int j = 0; j < bmp.PixelHeight; ++j)
  39. {
  40. // If all of the colors are 0x00, we change the pixel's color to magenta:
  41. if ((bmp[i, j] & 0x00FFFFFF) == 0)
  42. bmp[i, j] = 0xFFFF00FF;
  43. }
  44. // Draw the original image in the bottom right corner for reference:
  45. var rc = new RectangleF(0, 0, pixelSize.Width / 4, pixelSize.Height / 4);
  46. g.DrawImage(bmpSrc, rc, null, ImageAlign.StretchImage);
  47. g.DrawRectangle(rc, Color.LightGray);
  48. }
  49. }
  50. return bmp;
  51. }
  52. }
  53. }
  54.