这个程序是做中值滤波,但是显示的结果却出现错误。          Bitmap image1 = new Bitmap("C:\\Users\\ThinkPad\\Documents\\Visual Studio 2010\\Resources\\lena.bmp");
            BitmapData imageData1 = image1.LockBits(new Rectangle(0, 0, image1.Width, image1.Height), ImageLockMode.ReadWrite, image1.PixelFormat);
           
            
            int stride=imageData1.Stride;
            byte[] tempValue = new byte[9];
                
            int bytes =image1.Height * image1.Width;
            int width=3;
            int height=3;
            int halflength=width/2;
            byte[] grayValue = new byte[bytes];
            //unsafe
            //{
               IntPtr ptr = imageData1.Scan0;
                int offset = stride - (imageData1.Width) * 3;
                byte terry1, terry2, terry3, terry4, terry5, terry6, terry7, terry8, terry9;
                System.Runtime.InteropServices.Marshal.Copy(ptr, grayValue, 0, bytes);
                for (int i = halflength; i <imageData1.Height-1 ; i++)
                {
                    for (int j = halflength; j <imageData1.Width-1; j++)
                    {
                        terry1 =grayValue[(i-1)*image1.Width+(j-1)];
                        terry2 = grayValue[(i - 1) *image1.Width + (j)];
                        terry3 = grayValue[(i - 1) * image1.Width + (j+1)];
                        terry4 = grayValue[(i) * image1.Width + (j-1)];
                        terry5 = grayValue[(i) * image1.Width + (j)];
                        terry6 = grayValue[(i) * image1.Width + (j+1)];
                        terry7 = grayValue[(i+1) * image1.Width + (j - 1)];
                        terry8 = grayValue[(i+1) * image1.Width + (j)];
                        terry9 = grayValue[(i+1) * image1.Width + (j+1)];                        tempValue = new byte[] { terry1, terry2, terry3, terry4, terry5, terry6, terry7, terry8, terry9 };                        Sort(tempValue);
                        grayValue[i * image1.Width + j] = tempValue[5];
                        tempValue.Clone();
                                            }
                                  }           // }            System.Runtime.InteropServices.Marshal.Copy(grayValue,0, ptr, bytes);            image1.UnlockBits(imageData1);
           
           pictureBox2.Image = image1;[code=csharp][/code]