Exemple #1
0
        public static Color[,] InterpolateHeight(Color[,] img, int height)
        {
            if (height == img.GetLength(1))
            {
                return(img);
            }

            Color[,] nMatrix = new Color[img.GetLength(0), height];

            for (int i = 0; i < img.GetLength(0); i++)
            {
                Point lastIndex = new Point(0, 0);
                for (int j = 0; j < img.GetLength(1); j++)
                {
                    double percentY = (double)j / (double)img.GetLength(1);

                    int nY = (int)Math.Round(((double)nMatrix.GetLength(1) * (double)percentY));
                    if (nY >= nMatrix.GetLength(1))
                    {
                        nY = nMatrix.GetLength(1) - 1;
                    }
                    nMatrix[i, nY] = img[i, j];

                    for (int tY = lastIndex.Y + 1; tY < nY; tY++)
                    {
                        float time = (float)tY / (float)nY;
                        nMatrix[i, tY] = PixelTransform.InterpolateColor(nMatrix[lastIndex.X, lastIndex.Y], nMatrix[i, nY], time);
                    }
                    lastIndex = new Point(i, nY);
                }
            }

            return(nMatrix);
        }
Exemple #2
0
        public static Color[,] InterpolateWidth(Color[,] img, int width)
        {
            if (width == img.GetLength(0))
            {
                return(img);
            }

            Color[,] nMatrix = new Color[width, img.GetLength(1)];

            for (int j = 0; j < img.GetLength(1); j++)
            {
                Point lastIndex = new Point(0, 0);
                for (int i = 0; i < img.GetLength(0); i++)
                {
                    double percentX = (double)i / (double)img.GetLength(0);

                    int nX = (int)Math.Round(((double)nMatrix.GetLength(0) * (double)percentX));
                    if (nX >= nMatrix.GetLength(0))
                    {
                        nX = nMatrix.GetLength(0) - 1;
                    }

                    nMatrix[nX, j] = img[i, j];

                    for (int tX = lastIndex.X + 1; tX < nX; tX++)
                    {
                        float time = (float)tX / (float)nX;
                        nMatrix[tX, j] = PixelTransform.InterpolateColor(nMatrix[lastIndex.X, lastIndex.Y], nMatrix[nX, j], time);
                    }
                    lastIndex = new Point(nX, j);
                }
            }
            return(nMatrix);
        }