博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

图象处理算法(八)

Posted on 2007-03-05 15:53  faib  阅读(277)  评论(0编辑  收藏  举报
八、抖动
 1        public static bool Jitter(Bitmap b, int Offset)
 2        {
 3            BitmapData bmData = b.LockBits(new Rectangle(00, b.Width, b.Height), 
 4                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
 5            int stride = bmData.Stride;
 6            System.IntPtr Scan0 = bmData.Scan0;
 7            unsafe
 8            {
 9                byte * p = (byte *)(void *)Scan0;
10                byte * p1 = p;
11                int nOffset = stride - b.Width*3;
12                Random rad = new Random();
13                for(int y=0;y<b.Height;++y)
14                {
15                    for(int x=0; x < b.Width; ++x )
16                    {
17                        int xIn = rad.Next(2 * Offset + 1- Offset + x;
18                        int yIn = rad.Next(2 * Offset + 1- Offset + y;
19                        if((xIn >= 0&& (yIn >= 0&& (xIn < b.Width) && (yIn < b.Height))
20                        {
21                         byte * pTemp = p1 + stride * yIn + xIn * 3;
22                            for (int i = 0; i < 3; i++, p++)
23                            {
24                                *= pTemp[i];
25                            }

26                        }

27                        else
28                        {
29                            p += 3;
30                        }

31                    }

32                    p += nOffset;
33                }

34            }

35            b.UnlockBits(bmData);
36            return true;
37        }