Exemplo n.º 1
0
        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]);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void GetImageCopyTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(100, 100);
            Bitmap copy = adapter.GetImageCopy();

            Assert.AreNotEqual(copy, adapter.GetImage());
        }
Exemplo n.º 3
0
        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]);
                }
            }
        }
Exemplo n.º 4
0
        public void SetImageTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11);
            Bitmap picture = new Bitmap(5, 5);

            adapter.SetImage(picture);
            Assert.AreEqual(picture, adapter.GetImage());
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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());
        }
Exemplo n.º 7
0
        public void BitmapConcreteAdapterFailTest(int x, int y)
        {
            bool exceptionThrown = false;

            try
            {
                BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(x, y);
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
        }
Exemplo n.º 8
0
        public void LockBits2Test()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 10);
            bool exceptionThrown          = false;

            adapter.LockBits();
            try
            {
                adapter.LockBits();
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public void GetHeightTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11);

            Assert.AreEqual(11, adapter.GetHeight());
        }
Exemplo n.º 11
0
        public void GetWidthTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11);

            Assert.AreEqual(10, adapter.GetWidth());
        }
Exemplo n.º 12
0
 public void BitmapConcreteAdapterTest(int x, int y)
 {
     BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(x, y);
 }