public Image MaSaiKe(Image m_PreImage, int val)
        {
            Bitmap MyBitmap = new Bitmap(m_PreImage);
            if (MyBitmap.Equals(null))
            {
                return null;
            }
            int iWidth = MyBitmap.Width;
            int iHeight = MyBitmap.Height;
            int stdR, stdG, stdB;
            stdR = 0;
            stdG = 0;
            stdB = 0;
            BitmapData srcData = MyBitmap.LockBits(new Rectangle(0, 0, iWidth, iHeight),
            ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            unsafe
            {
                byte* point = (byte*)srcData.Scan0.ToPointer();
                for (int i = 0; i < iHeight; i++)
                {
                    for (int j = 0; j < iWidth; j++)
                    {
                        if (i % val == 0)
                        {
                            if (j % val == 0)
                            {
                                stdR = point[2];
                                stdG = point[1];
                                stdB = point[0];
                            }
                            else
                            {
                                point[0] = (byte)stdB;
                                point[1] = (byte)stdG;
                                point[2] = (byte)stdR;
                            }
                        }
                        else
                        {
                            //复制上一行  
                            byte* pTemp = point - srcData.Stride;
                            point[0] = (byte)pTemp[0];
                            point[1] = (byte)pTemp[1];
                            point[2] = (byte)pTemp[2];
                        }
                        point += 3;
                    }
                    point += srcData.Stride - iWidth * 3;
                }
                MyBitmap.UnlockBits(srcData);
            }
            return MyBitmap;
        }错误提示:
错误 1 不安全代码只会在使用 /unsafe 编译的情况下出现
这是怎么回事,我也想试试马赛克的效果哈~~,求大侠们帮助

解决方案 »

  1.   

    工程属性 -> Build 选项卡 -> Allow Unsafe code 勾选
      

  2.   

    难道说你看到的是这个?http://topic.csdn.net/u/20110411/12/4a44f138-b8f5-4d72-82eb-6b153eca360e.html?94403你问问lz不就可以了。
      

  3.   

    既然帖子提问了,答复一下:
    LZ我的代码上面写了这行 ,没看到么?(把错误放到Google一搜)
    这段代码使用了不安全代码,用了指针,要运行需要更改VS配置,Google下。看代码和效果:LZ要细心呀~~
      

  4.   

    工程属性(也就是你的类库上) -> 生成 -> 允许不安全代码   勾选上
      

  5.   

    如指针之类的代码必须再unsafe{     }中才可使用