我在写一段代码,要求使一幅图像能够沿X、Y轴移动指定的距离,或者能够作水平和垂直镜像,代码生成没有错误,可就是执行的时候只有图像上面一部分会移动和镜像,下面部分不会改变,这是为什么啊

解决方案 »

  1.   

    这个原理比较简单啊,首先在后台生成一个跟显示区域尺寸一样的Image,然后将要移动的图像在这个Image上绘制(根据移动的X,Y值变化图片绘制的坐标),最后将这个Image绘制在显示区域。通过线程来不停更新X/Y坐标,然后再绘制这个Image,这样看起来就像是在移动了。
      

  2.   

    public static Bitmap Flip(Bitmap bmp, FlipStyle flip)
            {
                if (flip == FlipStyle.NoFlip)
                    return bmp;            int width = bmp.Width;
                int height = bmp.Height;
                Bitmap res = new Bitmap(width, height);
                Graphics g = Graphics.FromImage(res);
                System.Drawing.Drawing2D.Matrix transform;//距阵            if (flip == FlipStyle.FlipX)
                {
                    transform = new Matrix(-1, 0, 0, 1, width, 0);
                }
                else if (flip == FlipStyle.FlipY)
                {
                    transform = new Matrix(1, 0, 0, -1, 0, height);
                }
                else if (flip == FlipStyle.FlipXY)
                {
                    transform = new Matrix(-1, 0, 0, -1, width, height);
                }
                else
                    transform = new Matrix(1, 0, 0, 1, width, height);            g.Transform = transform;
                g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, width, height),
                0, 0, width, height,
                GraphicsUnit.Pixel);
                //恢复绘图平面
                g.ResetTransform();
                g.Dispose();
                return res;
            }这是别人的代码
      

  3.   

    要自己写的也有,不过坑坑洼洼的,有写误差,有兴趣可以去查查双线性插值颜色估计,呵呵因为哥哥用不到,所以就不去完善了,加油!public static byte[] Evert(byte[] srcBufs, int w, int h, Straight stg)
            {
                int i, j;
                int idx;
                PointD foot;
                PointD pt;
                int nx,ny;
                int nlen = w * h;
                byte[] res = new byte[nlen];            for (i = 0; i < nlen; i++)
                    res[i] = 255;            for (i = 0; i < h; i++)
                {
                    for (j = 0; j < w; j++)
                    {
                        idx = i * w + j;
                        if (srcBufs[idx] == 0)
                        {
                            pt = new PointD(j, i);
                            foot = stg.Foot(pt);
                            pt = foot * 2 - pt;
                            nx = (int)(pt.X + 0.5);
                            ny = (int)(pt.Y + 0.5);
                            if (nx < w && ny < h && nx >= 0 && ny >= 0)
                            {
                                int nidx = nx + ny * w;
                                res[nidx] = 0;
                            }
                        }
                    }
                }                       return res;
            }        public static byte[] PatchEvert(byte[] srcBufs, int w, int h, Straight stg)
            {
                int i, j;
                int idx;
                PointD foot;
                PointD pt;
                int nx, ny;
                int nlen = w * h;
                byte[] res = new byte[nlen];            for (i = 0; i < nlen; i++)
                    res[i] = 255;            for (i = 0; i < h; i++)
                {
                    for (j = 0; j < w; j++)
                    {
                        idx = i * w + j;
                        if (srcBufs[idx] == 0)
                        {
                            pt = new PointD(j, i);
                            foot = stg.Foot(pt);
                            pt = foot * 2 - pt;
                            nx = (int)(pt.X + 0.5);
                            ny = (int)(pt.Y + 0.5);
                            if (nx < w && ny < h && nx >= 0 && ny >= 0)
                            {
                                int nidx = nx + ny * w;
                                res[nidx] = 0;
                            }
                        }
                    }
                }            byte[] rb = new byte[nlen];
                for (i = 0; i < nlen; i++)
                    rb[i] = 255;            int n;
                for (i = 1; i < h - 1; i++)
                {
                    for (j = 1; j < w - 1; j++)
                    {
                        idx = i * w + j;
                        if (res[idx] == 255)
                        {
                            n = 0;
                            if (res[idx - 1] == 0)
                                n++;
                            if (res[idx - w] == 0)
                                n++;
                            if (res[idx + 1] == 0)
                                n++;
                            if (res[idx + w] == 0)
                                n++;
                            if (n >= 2)
                                rb[idx] = 0;
                        }
                        else
                            rb[idx] = 0;
                    }
                }            return rb;
            }
      

  4.   

    关于
    pt = new PointD(j, i);
      foot = stg.Foot(pt);
      pt = foot * 2 - pt;
    这些诡异的代码,需要的话跟哥哥留个言,这个可以有!