ImageAttributes.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Sample application for ImageAttributes
  3. //
  4. // Author:
  5. // Jordi Mas i Hernàndez, [email protected]
  6. //
  7. using System;
  8. using System.Drawing;
  9. using System.Drawing.Drawing2D;
  10. using System.Drawing.Imaging;
  11. //
  12. public class SampleDrawingImage
  13. {
  14. /* DrawImageAbort callback method */
  15. static private bool DrawImageCallback(IntPtr callBackData)
  16. {
  17. Console.WriteLine("DrawImageCallback");
  18. return false;
  19. }
  20. public static void Main(string[] args)
  21. {
  22. Graphics.DrawImageAbort imageCallback;
  23. Bitmap outbmp = new Bitmap (600, 600);
  24. Bitmap bmp = new Bitmap("../../Test/System.Drawing/bitmaps/almogaver32bits.bmp");
  25. Graphics dc = Graphics.FromImage (outbmp);
  26. SolidBrush br = new SolidBrush(Color.White);
  27. Bitmap img = bmp.Clone (new Rectangle (0,0, 60,60) , PixelFormat.Format32bppArgb);
  28. ImageAttributes imageAttr = new ImageAttributes();
  29. Bitmap bmpred = new Bitmap (100,100, PixelFormat.Format32bppArgb);
  30. Graphics gr = Graphics.FromImage (bmpred);
  31. /* Sample drawing*/
  32. Pen cyan = new Pen(Color.Cyan, 0);
  33. Pen green = new Pen(Color.Green, 0);
  34. Pen pink = new Pen(Color.Pink, 0);
  35. Pen blue = new Pen(Color.Blue, 0);
  36. gr.DrawLine(cyan, 10.0F, 10.0F, 90.0F, 90.0F);
  37. gr.DrawLine(pink, 10.0F, 30.0F, 90.0F, 30.0F);
  38. gr.DrawLine(green, 10.0F, 50.0F, 90.0F, 50.0F);
  39. gr.DrawRectangle (blue, 10.0F, 10.0F, 80.0F, 80.0F);
  40. /* Draw image without any imageattributes*/
  41. dc.DrawImage (bmpred, 0,0);
  42. dc.DrawString ("Sample drawing", new Font ("Arial", 8), br, 10, 100);
  43. /* Remmaping colours */
  44. ColorMap[] clr = new ColorMap[1];
  45. clr[0] = new ColorMap();
  46. clr[0].OldColor = Color.Blue;
  47. clr[0].NewColor = Color.Yellow;
  48. imageAttr.SetRemapTable (clr, ColorAdjustType.Bitmap);
  49. dc.DrawImage (bmpred, new Rectangle (100, 0, 100,100), 0,0, 100,100, GraphicsUnit.Pixel, imageAttr);
  50. dc.DrawString ("Remapping colors", new Font ("Arial", 8), br, 110, 100);
  51. /* Gamma correction on*/
  52. imageAttr = new ImageAttributes();
  53. imageAttr.SetGamma (2);
  54. dc.DrawImage (bmpred, new Rectangle (200, 0, 100,100), 0,0,
  55. 100,100, GraphicsUnit.Pixel, imageAttr);
  56. dc.DrawString ("Gamma corrected", new Font ("Arial", 8), br, 210, 100);
  57. /* WrapMode: TitleX */
  58. imageAttr = new ImageAttributes();
  59. imageAttr.SetWrapMode (WrapMode.TileFlipX);
  60. dc.DrawImage (bmpred, new Rectangle (0, 120, 200, 200), 0,0,
  61. 200, 200, GraphicsUnit.Pixel, imageAttr);
  62. dc.DrawString ("WrapMode.TileFlipX", new Font ("Arial", 8), br, 10, 320);
  63. /* WrapMode: TitleY */
  64. imageAttr.SetWrapMode (WrapMode.TileFlipY);
  65. dc.DrawImage (bmpred, new Rectangle (200, 120, 200, 200), 0,0,
  66. 200, 200, GraphicsUnit.Pixel, imageAttr);
  67. dc.DrawString ("WrapMode.TileFlipY", new Font ("Arial", 8), br, 210, 320);
  68. /* WrapMode: TitleXY */
  69. imageAttr.SetWrapMode (WrapMode.TileFlipXY);
  70. dc.DrawImage (bmpred, new Rectangle (400, 120, 200, 200), 0,0,
  71. 200, 200, GraphicsUnit.Pixel, imageAttr);
  72. dc.DrawString ("WrapMode.TileFlipXY", new Font ("Arial", 8), br, 410, 320);
  73. outbmp.Save("imageattributes.bmp", ImageFormat.Bmp);
  74. }
  75. }