zoukankan      html  css  js  c++  java
  • [转]马赛克效果

     1 /// <summary>
     2         /// 马赛克效果
     3         ///原理:确定图像的随机位置点和确定马赛克块的大小,然后马赛克块图像覆盖随机点即可.
     4         /// </summary>
     5         /// <param name="m_Iimage"></param>
     6         /// <param name="val">分割成val*val像素的小区块</param>
     7         public Image MaSaiKe(Image m_PreImage , int val)
     8         {
     9             Bitmap MyBitmap = new Bitmap(m_PreImage);
    10             if (MyBitmap.Equals(null))
    11             {
    12                 return null;
    13             }
    14             int iWidth = MyBitmap.Width;
    15             int iHeight = MyBitmap.Height;
    16             int stdR , stdG , stdB;
    17             stdR = 0;
    18             stdG = 0;
    19             stdB = 0;
    20             BitmapData srcData = MyBitmap.LockBits(new Rectangle(0 , 0 , iWidth , iHeight) ,
    21             ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb);
    22             unsafe
    23             {
    24                 byte* point = (byte*)srcData.Scan0.ToPointer();
    25                 for (int i = 0; i < iHeight; i++)
    26                 {
    27                     for (int j = 0; j < iWidth; j++)
    28                     {
    29                         if (i % val == 0)
    30                         {
    31                             if (j % val == 0)
    32                             {
    33                                 stdR = point[2];
    34                                 stdG = point[1];
    35                                 stdB = point[0];
    36                             }
    37                             else
    38                             {
    39                                 point[0= (byte)stdB;
    40                                 point[1= (byte)stdG;
    41                                 point[2= (byte)stdR;
    42                             }
    43                         }
    44                         else
    45                         {
    46                             //复制上一行  
    47                             byte* pTemp = point - srcData.Stride;
    48                             point[0= (byte)pTemp[0];
    49                             point[1= (byte)pTemp[1];
    50                             point[2= (byte)pTemp[2];
    51                         }
    52                         point += 3;
    53                     }
    54                     point += srcData.Stride - iWidth * 3;
    55                 }
    56                 MyBitmap.UnlockBits(srcData);
    57             }
    58             return MyBitmap;
    59         }
  • 相关阅读:
    我的本科毕业论文——Messar即时通讯系统
    你为什么不用Flash做程序的表示层呢?
    用于Blog的天气预报服务-改进20050806
    写了个小程序,方便大家编程(QuickDog,快捷键帮手)
    庆祝"上海.NET俱乐部"今天成立,请申请加入的朋友在这里Sign you name
    HTML+CSS+Javascript教学视频【0409更新】
    关于推迟7月9日上海.NET俱乐部第一次技术交流会的通知
    关于“上海.NET俱乐部”第一次技术交流会进展报告
    2005年8月13日 上海.NET俱乐部第一次活动纪实 已经发布,资料提供下载
    喜欢互联网行业,是因为它拥有着无穷的变数
  • 原文地址:https://www.cnblogs.com/LeoWong/p/2013012.html
Copyright © 2011-2022 走看看