drawimage.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Sample application for drawing image implementation
  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 (300, 300);
  46. Bitmap bmp = new Bitmap("../../Test/System.Drawing/bitmaps/almogaver24bits.bmp");
  47. Graphics dc = Graphics.FromImage (outbmp);
  48. ImageAttributes imageAttr = new ImageAttributes();
  49. /* Simple image drawing */
  50. dc.DrawImage(bmp, 0,0);
  51. /* Drawing using points */
  52. PointF ulCorner = new PointF(150.0F, 0.0F);
  53. PointF urCorner = new PointF(350.0F, 0.0F);
  54. PointF llCorner = new PointF(200.0F, 150.0F);
  55. RectangleF srcRect = new Rectangle (0,0,100,100);
  56. PointF[] destPara = {ulCorner, urCorner, llCorner};
  57. imageCallback = new Graphics.DrawImageAbort(DrawImageCallback);
  58. dc.DrawImage (bmp, destPara, srcRect, GraphicsUnit.Pixel, imageAttr, imageCallback);
  59. /* Using rectangles */
  60. RectangleF destRect = new Rectangle (10,200,100,100);
  61. RectangleF srcRect2 = new Rectangle (50,50,100,100);
  62. dc.DrawImage (bmp, destRect, srcRect2, GraphicsUnit.Pixel);
  63. /* Simple image drawing with with scaling*/
  64. dc.DrawImage(bmp, 200,200, 75, 75);
  65. outbmp.Save("drawimage.bmp", ImageFormat.Bmp);
  66. }
  67. }