天天看點

Win8Metro(C#)數字圖像處理--2.16圖像浮雕效果



[函數名稱]

圖像浮雕效果函數ReliefProcess(WriteableBitmap

src)

Win8Metro(C#)數字圖像處理--2.16圖像浮雕效果

[函數代碼]

       ///<summary>

       ///

Relief process.

       ///</summary>

       ///<param

name="src">The source image.</param>

name="reliefValue">A value to adjust the relief processing, from 0 to 255.</param>

       ///<returns></returns>

       publicstaticWriteableBitmap

ReliefProcess(WriteableBitmap src,int

reliefValue)////16浮雕處理

       {

           if(src!=null

)

           {

           int

w = src.PixelWidth;

h = src.PixelHeight;

           WriteableBitmap

reliefImage =newWriteableBitmap(w,h);

           byte[]

temp = src.PixelBuffer.ToArray();

tempMask = (byte[])temp.Clone();

b = 0, g = 0, r = 0;

           for

(int j = 1; j < h - 1; j++)

               for

(int i = 4; i < w * 4 - 4; i += 4)

               {

                   b =Math.Abs(tempMask[i

+ j * w * 4] - tempMask[i + 4 + j * w * 4] + reliefValue);

                   g =Math.Abs(tempMask[i

+ 1 + j * w * 4] - tempMask[i + 1 + 4 + j * w * 4] + reliefValue);

                   r =Math.Abs(tempMask[i

+ 2 + j * w * 4] - tempMask[i + 2 + 4 + j * w * 4] + reliefValue);

                 temp[i + j * w * 4] = (byte)(b

> 0 ? (b < 255 ? b : 255) : 0);

                 temp[i + 1 + j * w * 4] = (byte)(g

> 0 ? (g < 255 ? g : 255) : 0);

                 temp[i + 2 + j * w * 4] = (byte)(r

> 0 ? (r < 255 ? r : 255) : 0);

                 b = 0; g = 0; r = 0;

               }

           }

           Stream

sTemp = reliefImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

           sTemp.Write(temp, 0, w * 4 * h);

           return

reliefImage;

           else

               returnnull;

           }  

       }

 [圖像效果]

Win8Metro(C#)數字圖像處理--2.16圖像浮雕效果

繼續閱讀