コード例 #1
0
ファイル: Program.cs プロジェクト: MatasGos/BMAN
        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]);
                    }
                }
            }
        }
コード例 #2
0
        public void GetImageCopyTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(100, 100);
            Bitmap copy = adapter.GetImageCopy();

            Assert.AreNotEqual(copy, adapter.GetImage());
        }
コード例 #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]);
                }
            }
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #10
0
        public void GetHeightTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11);

            Assert.AreEqual(11, adapter.GetHeight());
        }
コード例 #11
0
        public void GetWidthTest()
        {
            BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(10, 11);

            Assert.AreEqual(10, adapter.GetWidth());
        }
コード例 #12
0
 public void BitmapConcreteAdapterTest(int x, int y)
 {
     BitmapConcreteAdapter adapter = new BitmapConcreteAdapter(x, y);
 }