2 // JpegCodec class testing unit
6 // Jordi Mas i Hernàndez (jordi@ximian.com)
8 // (C) 2004 Ximian, Inc. http://www.ximian.com
12 using System.Drawing.Imaging;
13 using NUnit.Framework;
16 namespace MonoTests.System.Drawing
20 public class TestJpegCodec : Assertion
24 public void Clean() {}
27 public void GetReady()
32 /* Get the output directory depending on the runtime and location*/
33 internal string getOutSubDir()
37 if (Environment.GetEnvironmentVariable("MSNet")==null)
42 sRslt = Path.GetFullPath ("../System.Drawing/" + sSub);
44 if (Directory.Exists(sRslt) == false)
45 sRslt = "Test/System.Drawing/" + sSub;
48 if (sRslt[sRslt.Length-1] != '\\' && sRslt[sRslt.Length-1] != '/')
53 /* Get the input directory depending on the runtime*/
54 internal string getInFile(string file)
58 local = "../System.Drawing/" + file;
60 sRslt = Path.GetFullPath (local);
62 if (File.Exists(sRslt)==false)
63 sRslt = "Test/System.Drawing/" + file;
68 /* Checks bitmap features on a know 24-bits bitmap */
70 public void Bitmap24bitFeatures()
72 string sInFile = getInFile ("bitmaps/nature24bits.jpg");
73 Bitmap bmp = new Bitmap(sInFile);
75 GraphicsUnit unit = GraphicsUnit.World;
77 rect = bmp.GetBounds(ref unit);
79 AssertEquals (PixelFormat.Format24bppRgb, bmp.PixelFormat);
80 AssertEquals (110, bmp.Width);
81 AssertEquals (100, bmp.Height);
83 AssertEquals (0, rect.X);
84 AssertEquals (0, rect.Y);
85 AssertEquals (110, rect.Width);
86 AssertEquals (100, rect.Height);
88 AssertEquals (110, bmp.Size.Width);
89 AssertEquals (100, bmp.Size.Height);
96 string sOutFile = getOutSubDir() + "linerect.jpeg";
99 Bitmap bmp = new Bitmap(100,100, PixelFormat.Format32bppRgb);
100 Graphics gr = Graphics.FromImage(bmp);
102 Pen p = new Pen(Color.Red, 2);
103 gr.DrawLine(p, 10.0F, 10.0F, 90.0F, 90.0F);
104 gr.DrawRectangle(p, 10.0F, 10.0F, 80.0F, 80.0F);
106 bmp.Save(sOutFile, ImageFormat.Bmp);
111 Bitmap bmpLoad = new Bitmap(sOutFile);
113 Color color = bmpLoad.GetPixel(10,10);
115 AssertEquals (Color.FromArgb(255,255,0,0), color);