日期:2014-05-17  浏览次数:21167 次

【C#图像处理】关于水平镜像问题。菜鸟求助!
先上代码,在选择窗体里,如果选择水平镜像,点击确定后就进行水平镜像处理
  if (curBitmap != null)
            {
               //一个选择是否用水平镜像的窗体
                mirror mirForm = new mirror();
               
                if (mirForm.ShowDialog() == DialogResult.OK)
                {
                    Rectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height);
                    System.Drawing.Imaging.BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, curBitmap.PixelFormat);
                    IntPtr ptr = bmpData.Scan0;
                    int bytes = curBitmap.Width * curBitmap.Height*3;
                    byte[] grayValues = new byte[bytes];
                    System.Runtime.InteropServices.Marshal.Copy(ptr, grayValues, 0, bytes);

                    int halfWidth = curBitmap.Width / 2;
                    int halfHeight = curBitmap.Height / 2;
                    
                    byte temp;
//以上是获取图像,然后接着用内存法处理了

//主要的水平镜像处理就是在这里面了
 if (mirForm.GetMirror)
                    {
                         for (int i = 0; i < curBitmap.Height; i++)
                        {
                        //这里减3是因为我下面K还多出2个                         
                       for (int j = 0; j <=halfWidth*3-2; j=j+3)
         &