Esempio n. 1
0
        /// <summary>
        /// 四边形变换
        /// </summary>
        /// <param name="bmp">源位图</param>
        /// <param name="lt">左上角点</param>
        /// <param name="rt">右上角点</param>
        /// <param name="rb">右下角点</param>
        /// <param name="lb">左下角点</param>
        /// <returns></returns>
        public static Bitmap QuadrilateralTransform(Bitmap bmp, IntPoint lt, IntPoint rt, IntPoint rb, IntPoint lb)
        {
            // define quadrilateral's corners
            List <IntPoint> corners = new List <IntPoint>();

            corners.Add(lt);
            corners.Add(rt);
            corners.Add(rb);
            corners.Add(lb);
            // create filter
            BackwardQuadrilateralTransformation filter =
                new BackwardQuadrilateralTransformation(bmp, corners);
            Bitmap dest = new Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat);

            // apply the filter
            return(filter.Apply(dest));
        }
Esempio n. 2
0
        public static void CreateBackMappingPicture()
        {
            Bitmap target = new Bitmap(640, 480);
            Bitmap source = new Bitmap(640, 480);

            const int    size       = 1000;
            const double ratio      = 1.0 / size;
            const double saturation = 1.0;

            Color[,] colors = new Color[size, size];
            for (int x = 0; x < source.Width; x++)
            {
                double lightness = 1.0 - x * ratio;
                for (int y = 0; y < source.Height; y++)
                {
                    double hue = y * ratio;
                    //colors[x, y] = FromHSL(hue, saturation, lightness);
                }
            }

            source.Save(@"c:\temp\mapping.bmp");

            List <IntPoint> corners = new List <IntPoint>();

            corners.Add(new IntPoint(266, 480 - 410));
            corners.Add(new IntPoint(522, 480 - 353));
            corners.Add(new IntPoint(533, 480 - 147));
            corners.Add(new IntPoint(266, 480 - 167));


            BackwardQuadrilateralTransformation filter = new BackwardQuadrilateralTransformation(source, corners);
            // apply the filter
            Bitmap newImage = filter.Apply(target);

            newImage.Save(@"c:\temp\mappingback.bmp");
        }
        public static Bitmap Test(Bitmap bitmap)
        {
            BackwardQuadrilateralTransformation transformation = new BackwardQuadrilateralTransformation(bitmap, Corners);

            return(transformation.Apply(bitmap));
        }