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         }
  • 相关阅读:
    「BZOJ1061」 [Noi2008]志愿者招募
    [POJ 2891] Strange Way to Express Integers (扩展中国剩余定理)
    扩展中国剩余定理学习笔记
    扩展欧几里得算法+推论
    SPOJ16607 IE1
    [Luogu P4124] [CQOI2016]手机号码 (数位DP)
    [UOJ 275/BZOJ4737] 【清华集训2016】组合数问题 (LUCAS定理的运用+数位DP)
    一些很妙的网站
    [Luogu P3157][CQOI2011]动态逆序对 (树套树)
    [Luogu P3203] [HNOI2010]弹飞绵羊 (LCT维护链的长度)
  • 原文地址:https://www.cnblogs.com/LeoWong/p/2013012.html
Copyright © 2011-2022 走看看