ReadIco.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 GrapeCity.Documents.Drawing;
  11. using GrapeCity.Documents.Text;
  12. using GrapeCity.Documents.Imaging;
  13.  
  14. namespace DsImagingWeb.Demos
  15. {
  16. // This sample loads the .ICO generated by the MakeIco sample,
  17. // and renders all frames found in it along the diagonal of the
  18. // resulting image.
  19. public class ReadIco
  20. {
  21. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  22. {
  23. int x = 0, y = 0;
  24.  
  25. var srcPath = Path.Combine("Resources", "ImagesBis", "mescius-logomark-c.ico");
  26. using (var bmp = new GcBitmap())
  27. using (var ico = new GcIco(srcPath))
  28. {
  29. var w = ico.Frames.Sum(f_ => f_.Width);
  30. var h = ico.Frames.Sum(f_ => f_.Height);
  31. bmp.CreateImage(w, h, false);
  32. bmp.Clear();
  33. for (int i = 0; i < ico.Frames.Count; ++i)
  34. {
  35. using (var tbmp = ico.Frames[i].ToGcBitmap())
  36. {
  37. bmp.BitBlt(tbmp, x, y);
  38. x += tbmp.PixelWidth;
  39. y += tbmp.PixelHeight;
  40. }
  41. }
  42. return bmp.Clip(new Rectangle(0, 0, x, y));
  43. }
  44. }
  45. }
  46. }
  47.