zoukankan      html  css  js  c++  java
  • C#中马赛克算法

            public static Bitmap KiMosaic(Bitmap b, int val)
            {
                
    if (b.Equals(null)) { return null; }

                
    int w = b.Width; 
                
    int h = b.Height;
                
    int stdR, stdG, stdB;
                stdR 
    = 0; stdG = 0; stdB = 0;

                BitmapData srcData 
    = b.LockBits(new Rectangle(00, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                
    unsafe
                {
                    
    byte* p = (byte*)srcData.Scan0.ToPointer();
                    
    for (int y = 0; y < h; y++)
                    {
                        
    for (int x = 0; x < w; x++)
                        {
                            
    if (y % val == 0)
                            {
                                
    if (x % val == 0) { stdR = p[2]; stdG = p[1]; stdB = p[0]; }
                                
    else { p[0= (byte)stdB; p[1= (byte)stdG; p[2= (byte)stdR; }
                            }
                            
    else
                            {  
                                
    byte* pTemp = p - srcData.Stride;
                                p[
    0= (byte)pTemp[0]; 
                                p[
    1= (byte)pTemp[1];
                                p[
    2= (byte)pTemp[2];
                            } p 
    += 3;
                        }
                        p 
    += srcData.Stride - w * 3;
                    }
                    b.UnlockBits(srcData);
                }
                
    return b;
            }
  • 相关阅读:
    UVA 1386 Cellular Automaton
    ZOJ 3331 Process the Tasks
    CodeForces 650B Image Preview
    CodeForces 650A Watchmen
    CodeForces 651B Beautiful Paintings
    CodeForces 651A Joysticks
    HUST 1601 Shepherd
    HUST 1602 Substring
    HUST 1600 Lucky Numbers
    POJ 3991 Seinfeld
  • 原文地址:https://www.cnblogs.com/limlee/p/1616829.html
Copyright © 2011-2022 走看看