小弟写了一个图片镜像的代码,但是运行总是出错,大家帮忙看看private void 水平镜像ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            box = new Bitmap(pictureBox1.Image);
            width = pictureBox1.Image.Width;
            height = pictureBox1.Image.Height;
            Graphics g = pictureBox1.CreateGraphics();
            Bitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
            g.Clear(this.BackColor);
            Color c = new Color(); ;
            for (x = 0; x < width; x++)
            {
                for (y = 0; y < height; y++)
                {
                    c = box.GetPixel(x, y);
                    bmp.SetPixel(width - 1 - x, y, c);
                }
            }
            pictureBox1.Image = bmp;
        }

解决方案 »

  1.   

     width = pictureBox1.Image.Width;
      height = pictureBox1.Image.Height;
    to::
     width = box.Width;
      height = box.Height;ANDBitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
    to::
    Bitmap bmp = new Bitmap(width , height );
      

  2.   

    如果只是镜像,那么:Bitmap bmp = new Bitmap(pictureBox1.Image);
    bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
    pictureBox1.Image = bmp;
      

  3.   

    private void 垂直镜像ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                box = new Bitmap(pictureBox1.Image);
                width = pictureBox1.Image.Width;
                height = pictureBox1.Image.Height;
                Graphics g = pictureBox1.CreateGraphics();
                Bitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
                g.Clear(this.BackColor);
                Color c = new Color(); ;
                for (x = 0; x < width; x++)
                {
                    for (y = 0; y < height; y++)
                    {
                        c = box.GetPixel(x, y);
                        bmp.SetPixel(x, height - 1 - y, c);
                    }
                }
                pictureBox1.Image = bmp;
            }