C# – Imaging – XYMosaic (XY馬賽克)

來源:互聯網
上載者:User
寫此段代碼的原因是為了證明坎子的程式的可最佳化性,隨寫此代碼~~~當然,上班時間偷閑的匆匆之作,My Code依然可最佳化~~~比如用填充的方法填充一個單一顏色的位元影像,然後排布這個位元影像,來做馬賽克效果~~~

誰有心思,寫一個吧~~

^_^

坎子的代碼:http://www.cnblogs.com/iceshark/archive/2004/12/12/75362.html

更新了一下,去掉了BUG一處~~
        XYMosaic( Bitmap ObjectBitmap , uint Stride )#region XYMosaic( Bitmap ObjectBitmap , uint Stride )


        public static void XYMosaic(Bitmap ObjectBitmap, uint Stride) 

        { 

            if(ObjectBitmap.Equals(null)) 

            { 

                new Exception("The Bitmap is null."); 

            } 

            try 

            { 

                int stride = (int)Stride; 

                int centerW = (stride - 1) / 2;;

                int centerH = centerW;

                int newH = ObjectBitmap.Height / stride + 1; 

                int newW = ObjectBitmap.Width / stride + 1; 

                int tmpH, tmpW;

                int lW = ObjectBitmap.Width % stride;

                int lH = ObjectBitmap.Height % stride;

                int ti, tj;

                Color c; 

                for(int w = 0; w < newW; w++) 

                { 

                    tmpW = w * stride; 

                    if(w.Equals(newW - 1))

                    {

                        ti = lW;

                    }

                    else

                    {

                        ti = stride;

                    }

                    centerW = (ti - 1) / 2; 

                    for(int h = 0; h < newH; h++) 

                    { 

                        tmpH = h * stride;                    

                        if(h.Equals(newH - 1))

                        {

                            tj = lH;

                        }

                        else

                        {

                            tj = stride;

                        }

                        centerH = (tj - 1) / 2; 

                        c = ObjectBitmap.GetPixel(tmpW + centerW, tmpH + centerH); 

                        for(int i = 0; i < ti; i++) 

                        { 

                            for(int j = 0; j < tj; j++) 

                            { 

                                ObjectBitmap.SetPixel(tmpW + i, tmpH + j, c); 

                            } 

                        }

                    }

                } 

            } 

            catch(Exception e) 

            { 

                new Exception("Mosaic Error", e); 

            } 

        }


        #endregion 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.