BmpTransforms.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 demonstrates how to use bitmap transformations
  17. // such as resizing, flipping and rotating.
  18. public class Transforms
  19. {
  20. public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
  21. {
  22. var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);
  23. bmp.Clear(Color.Transparent);
  24.  
  25. var side = pixelSize.Width / 2;
  26. var side2 = side / 2;
  27. GcBitmap bmpLarge, bmpFlip, bmpSmall1, bmpSmall2, bmpSmall3, bmpSmall4;
  28. using (var bmpSrc = new GcBitmap(Path.Combine("Resources", "Stock", "goldfish.jpg")))
  29. {
  30. bmpSrc.Opaque = opaque;
  31. bmpLarge = bmpSrc.Resize(side, side);
  32. bmpFlip = bmpLarge.FlipRotate(FlipRotateAction.FlipHorizontal);
  33. bmpSmall1 = bmpSrc.Resize(side2, side2);
  34. bmpSmall2 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate270);
  35. bmpSmall3 = bmpSmall1.FlipRotate(FlipRotateAction.FlipVertical);
  36. bmpSmall4 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate90);
  37. }
  38.  
  39. bmp.BitBlt(bmpLarge, 0, 0);
  40. bmp.BitBlt(bmpFlip, (int)(pixelSize.Width - bmpFlip.Width), 0);
  41. bmp.BitBlt(bmpSmall1, 0, side + side2 / 2);
  42. bmp.BitBlt(bmpSmall2, side2, side + side2 / 2);
  43. bmp.BitBlt(bmpSmall3, side2 * 2, side + side2 / 2);
  44. bmp.BitBlt(bmpSmall4, side2 * 3, side + side2 / 2);
  45.  
  46. // Dispose bitmaps except the resulting one:
  47. bmpLarge.Dispose();
  48. bmpFlip.Dispose();
  49. bmpSmall1.Dispose();
  50. bmpSmall2.Dispose();
  51. bmpSmall3.Dispose();
  52. bmpSmall4.Dispose();
  53.  
  54. return bmp;
  55. }
  56. }
  57. }
  58.