ImageAttributes.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // Sample application for ImageAttributes
  3. //
  4. // Author:
  5. // Jordi Mas i Hernàndez, [email protected]
  6. //
  7. //
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Drawing;
  31. using System.Drawing.Drawing2D;
  32. using System.Drawing.Imaging;
  33. //
  34. public class SampleDrawingImage
  35. {
  36. /* DrawImageAbort callback method */
  37. static private bool DrawImageCallback(IntPtr callBackData)
  38. {
  39. Console.WriteLine("DrawImageCallback");
  40. return false;
  41. }
  42. public static void Main(string[] args)
  43. {
  44. Graphics.DrawImageAbort imageCallback;
  45. Bitmap outbmp = new Bitmap (600, 600);
  46. Bitmap bmp = new Bitmap("../../Test/System.Drawing/bitmaps/almogaver32bits.bmp");
  47. Graphics dc = Graphics.FromImage (outbmp);
  48. SolidBrush br = new SolidBrush(Color.White);
  49. Bitmap img = bmp.Clone (new Rectangle (0,0, 60,60) , PixelFormat.Format32bppArgb);
  50. ImageAttributes imageAttr = new ImageAttributes();
  51. Bitmap bmpred = new Bitmap (100,100, PixelFormat.Format32bppArgb);
  52. Graphics gr = Graphics.FromImage (bmpred);
  53. /* Sample drawing*/
  54. Pen cyan = new Pen(Color.Cyan, 0);
  55. Pen green = new Pen(Color.Green, 0);
  56. Pen pink = new Pen(Color.Pink, 0);
  57. Pen blue = new Pen(Color.Blue, 0);
  58. gr.DrawLine(cyan, 10.0F, 10.0F, 90.0F, 90.0F);
  59. gr.DrawLine(pink, 10.0F, 30.0F, 90.0F, 30.0F);
  60. gr.DrawLine(green, 10.0F, 50.0F, 90.0F, 50.0F);
  61. gr.DrawRectangle (blue, 10.0F, 10.0F, 80.0F, 80.0F);
  62. /* Draw image without any imageattributes*/
  63. dc.DrawImage (bmpred, 0,0);
  64. dc.DrawString ("Sample drawing", new Font ("Arial", 8), br, 10, 100);
  65. /* Remmaping colours */
  66. ColorMap[] clr = new ColorMap[1];
  67. clr[0] = new ColorMap();
  68. clr[0].OldColor = Color.Blue;
  69. clr[0].NewColor = Color.Yellow;
  70. imageAttr.SetRemapTable (clr, ColorAdjustType.Bitmap);
  71. dc.DrawImage (bmpred, new Rectangle (100, 0, 100,100), 0,0, 100,100, GraphicsUnit.Pixel, imageAttr);
  72. dc.DrawString ("Remapping colors", new Font ("Arial", 8), br, 110, 100);
  73. /* Gamma correction on*/
  74. imageAttr = new ImageAttributes();
  75. imageAttr.SetGamma (2);
  76. dc.DrawImage (bmpred, new Rectangle (200, 0, 100,100), 0,0,
  77. 100,100, GraphicsUnit.Pixel, imageAttr);
  78. dc.DrawString ("Gamma corrected", new Font ("Arial", 8), br, 210, 100);
  79. /* WrapMode: TitleX */
  80. imageAttr = new ImageAttributes();
  81. imageAttr.SetWrapMode (WrapMode.TileFlipX);
  82. dc.DrawImage (bmpred, new Rectangle (0, 120, 200, 200), 0,0,
  83. 200, 200, GraphicsUnit.Pixel, imageAttr);
  84. dc.DrawString ("WrapMode.TileFlipX", new Font ("Arial", 8), br, 10, 320);
  85. /* WrapMode: TitleY */
  86. imageAttr.SetWrapMode (WrapMode.TileFlipY);
  87. dc.DrawImage (bmpred, new Rectangle (200, 120, 200, 200), 0,0,
  88. 200, 200, GraphicsUnit.Pixel, imageAttr);
  89. dc.DrawString ("WrapMode.TileFlipY", new Font ("Arial", 8), br, 210, 320);
  90. /* WrapMode: TitleXY */
  91. imageAttr.SetWrapMode (WrapMode.TileFlipXY);
  92. dc.DrawImage (bmpred, new Rectangle (400, 120, 200, 200), 0,0,
  93. 200, 200, GraphicsUnit.Pixel, imageAttr);
  94. dc.DrawString ("WrapMode.TileFlipXY", new Font ("Arial", 8), br, 410, 320);
  95. outbmp.Save("imageattributes.bmp", ImageFormat.Bmp);
  96. }
  97. }