Csharp:白底圖片透明處理

 1 Bitmap bmp = new Bitmap(pictureBox1.Image, pictureBox1.Image.Size);
 2                 BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);
 3                 int length = data.Stride * data.Height;
 4                 IntPtr ptr = data.Scan0;
 5                 byte[] buff = new byte[length];
 6                 Marshal.Copy(ptr, buff, 0, length);
 7                 for (int i = 3; i < length; i += 4)
 8                 {
 9                     if (buff[i - 1] >= 230 && buff[i - 2] >= 230 && buff[i - 3] >= 230)
10                     {
11                         buff[i] = 0;
12                     }
13                 }
14                 Marshal.Copy(buff, 0, ptr, length);
15                 bmp.UnlockBits(data);

 

posted @ 2013-03-25 18:51  ®Geovin Du Dream Park™  阅读(875)  评论(0编辑  收藏  举报