TestJpegCodec.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // JpegCodec class testing unit
  3. //
  4. // Author:
  5. //
  6. // Jordi Mas i Hernàndez ([email protected])
  7. //
  8. // (C) 2004 Ximian, Inc. http://www.ximian.com
  9. //
  10. using System;
  11. using System.Drawing;
  12. using System.Drawing.Imaging;
  13. using NUnit.Framework;
  14. using System.IO;
  15. namespace MonoTests.System.Drawing
  16. {
  17. [TestFixture]
  18. public class TestJpegCodec : Assertion
  19. {
  20. [TearDown]
  21. public void Clean() {}
  22. [SetUp]
  23. public void GetReady()
  24. {
  25. }
  26. /* Get the output directory depending on the runtime and location*/
  27. internal string getOutSubDir()
  28. {
  29. string sSub, sRslt;
  30. if (Environment.GetEnvironmentVariable("MSNet")==null)
  31. sSub = "mono/";
  32. else
  33. sSub = "MSNet/";
  34. sRslt = Path.GetFullPath ("../System.Drawing/" + sSub);
  35. if (Directory.Exists(sRslt) == false)
  36. sRslt = "Test/System.Drawing/" + sSub;
  37. if (sRslt.Length > 0)
  38. if (sRslt[sRslt.Length-1] != '\\' && sRslt[sRslt.Length-1] != '/')
  39. sRslt += "/";
  40. return sRslt;
  41. }
  42. /* Get the input directory depending on the runtime*/
  43. internal string getInFile(string file)
  44. {
  45. string sRslt, local;
  46. local = "../System.Drawing/" + file;
  47. sRslt = Path.GetFullPath (local);
  48. if (File.Exists(sRslt)==false)
  49. sRslt = "Test/System.Drawing/" + file;
  50. return sRslt;
  51. }
  52. /* Checks bitmap features on a know 24-bits bitmap */
  53. [Test]
  54. public void Bitmap24bitFeatures()
  55. {
  56. string sInFile = getInFile ("bitmaps/nature24bits.jpg");
  57. Bitmap bmp = new Bitmap(sInFile);
  58. RectangleF rect;
  59. GraphicsUnit unit = GraphicsUnit.World;
  60. rect = bmp.GetBounds(ref unit);
  61. AssertEquals (PixelFormat.Format24bppRgb, bmp.PixelFormat);
  62. AssertEquals (110, bmp.Width);
  63. AssertEquals (100, bmp.Height);
  64. AssertEquals (0, rect.X);
  65. AssertEquals (0, rect.Y);
  66. AssertEquals (110, rect.Width);
  67. AssertEquals (100, rect.Height);
  68. AssertEquals (110, bmp.Size.Width);
  69. AssertEquals (100, bmp.Size.Height);
  70. }
  71. [Test]
  72. public void Save()
  73. {
  74. string sOutFile = getOutSubDir() + "linerect.jpeg";
  75. // Save
  76. Bitmap bmp = new Bitmap(100,100, PixelFormat.Format32bppRgb);
  77. Graphics gr = Graphics.FromImage(bmp);
  78. Pen p = new Pen(Color.Red, 2);
  79. gr.DrawLine(p, 10.0F, 10.0F, 90.0F, 90.0F);
  80. gr.DrawRectangle(p, 10.0F, 10.0F, 80.0F, 80.0F);
  81. p.Dispose();
  82. bmp.Save(sOutFile, ImageFormat.Bmp);
  83. gr.Dispose();
  84. bmp.Dispose();
  85. // Load
  86. Bitmap bmpLoad = new Bitmap(sOutFile);
  87. Color color = bmpLoad.GetPixel(10,10);
  88. AssertEquals (Color.FromArgb(255,255,0,0), color);
  89. }
  90. }
  91. }