예제 #1
0
        public static Bitmap Transformation(this Bitmap bitmap, Bitmap reference, double[,] mat)
        {
            /*
             * int offsetX = (int) mat[2, 0];
             * int offsetY = (int) mat[2, 1];
             * double scaleX = Math.Sqrt(Math.Pow(mat[0, 0], 2) + Math.Pow(mat[0, 1], 2));
             * double scaleY = Math.Sqrt(Math.Pow(mat[1, 0], 2) + Math.Pow(mat[1, 1], 2));
             * double theta = Math.Atan(mat[0, 1] / mat[0, 0]);
             *
             * int width = (int) Math.Ceiling((bitmap.Width - offsetX) / Math.Cos(theta) / scaleX);
             * int height = (int) Math.Ceiling(offsetX / Math.Sin(theta) / scaleY);
             */

            Bitmap change = new Bitmap(reference.Width, reference.Height);

            CustomMatrix customMatrix = new CustomMatrix();

            for (int i = 0; i < change.Width; i++)
            {
                for (int j = 0; j < change.Height; j++)
                {
                    double[,] coordinate = new double[1, 3]
                    {
                        { i, j, 1 }
                    };

                    coordinate = customMatrix.MatrixMultiply(coordinate, mat);
                    int x = (int)Math.Round(coordinate[0, 0]);
                    int y = (int)Math.Round(coordinate[0, 1]);

                    if (x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)
                    {
                        Color color = bitmap.GetPixel(x, y);

                        change.SetPixel(i, j, color);
                    }
                }
            }

            return(change);
        }
예제 #2
0
        public void TestMethodMultiply()
        {
            var arr1 = new int[1, 3]
            {
                { 1, 2, 3 },
            };

            var arr2 = new int[3, 3]
            {
                { 1, 2, 3 },
                { 1, 2, 3 },
                { 1, 2, 3 }
            };

            var ret    = matrix.MatrixMultiply <int>(arr1, arr2);
            var result = new Int32[1, 3]
            {
                { 6, 12, 18 },
            };

            Assert.AreEqual(result, ret, "Multiply Error");
        }