日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图像处理之玻璃水印特效(祝大家圣诞节快乐)

發(fā)布時間:2025/7/25 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像处理之玻璃水印特效(祝大家圣诞节快乐) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

from:http://blog.csdn.net/jia20003/article/details/13159535


Water Ripple Effect - 水波紋效果

一:原理

模擬水波紋效果,最常見的是sine或者cosn的函數(shù),周期性變化,貼近自然

當(dāng)水波紋中中間開始向四周擴(kuò)散的時候,一般都是慢慢的失去能量,振幅也是

越來越小,所以程序要模擬這個過程時候,要加上一個能量遞減因子。然后用

公式 y = a*sine(bx + c)來表示波紋公式。

二:程序?qū)崿F(xiàn)

最重要的一步是計(jì)算水波紋的振幅。在任意一點(diǎn)確定水波的中心位置,可以是

鼠標(biāo)隨機(jī)選取,對半徑范圍內(nèi)的像素位置實(shí)現(xiàn)水波生成,然后轉(zhuǎn)換為位置,對

位置實(shí)現(xiàn)浮點(diǎn)數(shù)取整,然后使用適當(dāng)?shù)牟逯邓惴?#xff0c;本例使用雙線性插值。

三:程序效果


四:濾鏡完全源代碼,這次我寫了些中文注解,不給源代碼的博文不是好博文

[java] view plaincopy
  • package?com.gloomyfish.filter.study;??
  • ??
  • import?java.awt.image.BufferedImage;??
  • ??
  • public?class?WaterFilter?extends?AbstractBufferedImageOp?{??
  • ????private?float?wavelength?=?16;??
  • ????private?float?amplitude?=?10;??
  • ????private?float?phase?=?0;??
  • ????private?float?centreX?=?0.5f;??
  • ????private?float?centreY?=?0.5f;??
  • ????private?float?radius?=?50;??
  • ??
  • ????private?float?radius2?=?0;??
  • ????private?float?icentreX;??
  • ????private?float?icentreY;??
  • ??????
  • ????public?WaterFilter()?{??
  • ??
  • ????}??
  • ??
  • ????@Override??
  • ????public?BufferedImage?filter(BufferedImage?src,?BufferedImage?dest)?{??
  • ????????int?width?=?src.getWidth();??
  • ????????int?height?=?src.getHeight();??
  • ??
  • ????????if?(?dest?==?null?)??
  • ????????????dest?=?createCompatibleDestImage(?src,?null?);??
  • ??
  • ????????int[]?inPixels?=?new?int[width*height];??
  • ????????int[]?outPixels?=?new?int[width*height];??
  • ????????getRGB(?src,?0,?0,?width,?height,?inPixels?);??
  • ????????icentreX?=?width?*?centreX;??
  • ????????icentreY?=?height?*?centreY;??
  • ????????if?(?radius?==?0?)??
  • ????????????radius?=?Math.min(icentreX,?icentreY);??
  • ????????radius2?=?radius*radius;??
  • ????????int?index?=?0;??
  • ????????float[]?out?=?new?float[2];??
  • ????????for(int?row=0;?row<height;?row++)?{??
  • ????????????for(int?col=0;?col<width;?col++)?{??
  • ????????????????index?=?row?*?width?+?col;??
  • ??????????????????
  • ????????????????//?獲取水波的擴(kuò)散位置,最重要的一步??
  • ????????????????generateWaterRipples(col,?row,?out);??
  • ????????????????int?srcX?=?(int)Math.floor(?out[0]?);??
  • ????????????????int?srcY?=?(int)Math.floor(?out[1]?);??
  • ????????????????float?xWeight?=?out[0]-srcX;??
  • ????????????????float?yWeight?=?out[1]-srcY;??
  • ????????????????int?nw,?ne,?sw,?se;??
  • ??????????????????
  • ????????????????//?獲取周圍四個像素,插值用,??
  • ????????????????if?(?srcX?>=?0?&&?srcX?<?width-1?&&?srcY?>=?0?&&?srcY?<?height-1)?{??
  • ????????????????????//?Easy?case,?all?corners?are?in?the?image??
  • ????????????????????int?i?=?width*srcY?+?srcX;??
  • ????????????????????nw?=?inPixels[i];??
  • ????????????????????ne?=?inPixels[i+1];??
  • ????????????????????sw?=?inPixels[i+width];??
  • ????????????????????se?=?inPixels[i+width+1];??
  • ????????????????}?else?{??
  • ????????????????????//?Some?of?the?corners?are?off?the?image??
  • ????????????????????nw?=?getPixel(?inPixels,?srcX,?srcY,?width,?height?);??
  • ????????????????????ne?=?getPixel(?inPixels,?srcX+1,?srcY,?width,?height?);??
  • ????????????????????sw?=?getPixel(?inPixels,?srcX,?srcY+1,?width,?height?);??
  • ????????????????????se?=?getPixel(?inPixels,?srcX+1,?srcY+1,?width,?height?);??
  • ????????????????}??
  • ??????????????????
  • ????????????????//?取得對應(yīng)的振幅位置P(x,?y)的像素,使用雙線性插值??
  • ????????????????/*if(xWeight?>=0?||?yWeight?>=?0)?
  • ????????????????{?
  • ????????????????????outPixels[index]?=?ImageMath.bilinearInterpolate(xWeight,?yWeight,?nw,?ne,?sw,?se);??????????????????
  • ????????????????}?
  • ????????????????else??
  • ????????????????{?
  • ????????????????????outPixels[index]?=?inPixels[index];?
  • ????????????????}*/??
  • ????????????????outPixels[index]?=?ImageMath.bilinearInterpolate(xWeight,?yWeight,?nw,?ne,?sw,?se);??
  • ????????????}??
  • ????????}??
  • ??
  • ????????setRGB(?dest,?0,?0,?width,?height,?outPixels?);??
  • ????????return?dest;??
  • ????}??
  • ??
  • ????private?int?getPixel(int[]?pixels,?int?x,?int?y,?int?width,?int?height)?{??
  • ????????if?(x?<?0?||?x?>=?width?||?y?<?0?||?y?>=?height)?{??
  • ????????????return?0;?//?有點(diǎn)暴力啦,懶得管啦??
  • ????????}??
  • ????????return?pixels[?y*width+x?];??
  • ????}??
  • ??
  • ????protected?void?generateWaterRipples(int?x,?int?y,?float[]?out)?{??
  • ????????float?dx?=?x-icentreX;??
  • ????????float?dy?=?y-icentreY;??
  • ????????float?distance2?=?dx*dx?+?dy*dy;??
  • ????????//?確定?water?ripple的半徑,如果在半徑之外,就直接獲取原來位置,不用計(jì)算遷移量??
  • ????????if?(distance2?>?radius2)?{???
  • ????????????out[0]?=?x;??
  • ????????????out[1]?=?y;??
  • ????????}?else?{??
  • ????????????//?如果在radius半徑之內(nèi),計(jì)算出來??
  • ????????????float?distance?=?(float)Math.sqrt(distance2);??
  • ????????????//?計(jì)算改點(diǎn)振幅??
  • ????????????float?amount?=?amplitude?*?(float)Math.sin(distance?/?wavelength?*?ImageMath.TWO_PI?-?phase);??
  • ????????????//?計(jì)算能量損失,???
  • ????????????amount?*=?(radius-distance)/radius;?//?計(jì)算能量損失,??
  • ????????????if?(?distance?!=?0?)??
  • ????????????????amount?*=?wavelength/distance;??
  • ????????????//?得到water?ripple?最終遷移位置??
  • ????????????out[0]?=?x?+?dx*amount;??
  • ????????????out[1]?=?y?+?dy*amount;??
  • ????????}??
  • ????}??
  • ??????
  • }??
  • 覺得不錯請頂一下,謝謝!

    轉(zhuǎn)載請務(wù)必注明出處!謝謝!

    《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

    總結(jié)

    以上是生活随笔為你收集整理的图像处理之玻璃水印特效(祝大家圣诞节快乐)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。