ShowHiClipping.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
  18. // pixels with blown out highlights.
  19. public class ShowHiClipping
  20. {
  21. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  22. {
  23. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
  24. using (var bmpSrc = new GcBitmap(Path.Combine("Resources", "Images", "tudor.jpg")))
  25. {
  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 (var g = bmp.CreateGraphics())
  35. {
  36. for (int i = 0; i < bmp.PixelWidth; ++i)
  37. for (int j = 0; j < bmp.PixelHeight; ++j)
  38. {
  39. uint px = bmp[i, j];
  40. // If any of the colors are 0xFF, we change the pixel's color to magenta:
  41. if ((px & 0x000000FF) == 0x000000FF || (px & 0x0000FF00) == 0x0000FF00 || (px & 0x00FF0000) == 0x00FF0000)
  42. bmp[i, j] = 0xFFFF00FF;
  43. }
  44. // Draw the original image in the bottom right corner for reference:
  45. float sx = pixelSize.Width / 3, sy = pixelSize.Height / 3;
  46. g.DrawImage(bmpSrc, new RectangleF(sx * 2, sy * 2, sx, sy), null, ImageAlign.StretchImage);
  47. }
  48. }
  49. return bmp;
  50. }
  51. }
  52. }
  53.