public static void AdapterDemo() { GraphicsAdapter <Bitmap, Color> graphics = new BitmapConcreteAdapter(5, 5); graphics.LockBits(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { graphics.SetPixel(i, j, Color.Blue); } } graphics.UnlockBits(); Color[,] pixels = graphics.GetColorArray(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (j != 4) { Console.Write(pixels[i, j] + " | "); } else { Console.WriteLine(pixels[i, j]); } } } }
public void GetImageCopyTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(100, 100); Bitmap copy = adapter.GetImageCopy(); Assert.AreNotEqual(copy, adapter.GetImage()); }
public void GetColorArrayTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 10); Bitmap picture1 = adapter.GetImage(); adapter.LockBits(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { adapter.SetPixel(i, j, Color.Red); } } adapter.UnlockBits(); Color[,] colorArray = adapter.GetColorArray(); Bitmap picture = adapter.GetImage(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Assert.AreEqual(picture.GetPixel(i, j), colorArray[i, j]); } } }
public void SetImageTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11); Bitmap picture = new Bitmap(5, 5); adapter.SetImage(picture); Assert.AreEqual(picture, adapter.GetImage()); }
public void GetImageTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(100, 100); Bitmap picture = adapter.GetImage(); Assert.IsNotNull(picture); Assert.AreEqual(100, picture.Width); Assert.AreEqual(100, picture.Height); }
public void SetPixelTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 10); Bitmap picture1 = adapter.GetImage(); adapter.LockBits(); adapter.SetPixel(0, 0, Color.Red); adapter.UnlockBits(); Assert.AreEqual(Color.Red.ToArgb(), picture1.GetPixel(0, 0).ToArgb()); }
public void BitmapConcreteAdapterFailTest(int x, int y) { bool exceptionThrown = false; try { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(x, y); } catch { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); }
public void LockBits2Test() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 10); bool exceptionThrown = false; adapter.LockBits(); try { adapter.LockBits(); } catch { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); }
public void LockBitsTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 10); Bitmap picture1 = adapter.GetImage(); adapter.LockBits(); bool exceptionThrown = false; try { picture1.GetPixel(0, 0); } catch { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); }
public void GetHeightTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11); Assert.AreEqual(11, adapter.GetHeight()); }
public void GetWidthTest() { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11); Assert.AreEqual(10, adapter.GetWidth()); }
public void BitmapConcreteAdapterTest(int x, int y) { BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(x, y); }