霓虹是用來(lái)描繪圖像的輪廓,勾畫(huà)出顏色變化的邊緣,加強(qiáng)其過(guò)度效果,使圖像產(chǎn)生輪廓發(fā)光的效果。
主要步驟為
1、根據(jù)當(dāng)前像素與其右方和下方像素的梯度運(yùn)算;
2、然后將結(jié)果值作為當(dāng)前像素值,即將原圖當(dāng)前下像素的RGB分量與其右方和下方像素做梯度 運(yùn)算(差的平方和平方根);
3、然后將梯度值作為處理后的像素的RGB三個(gè)分量;
用代碼實(shí)現(xiàn)如下:
//霓虹 public static Bitmap Neon(Bitmap bitmap){ int w = bitmap.getWidth(); int h = bitmap.getHeight(); Bitmap resultBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565); int color = 0; int r,g,b,r1,g1,b1,r2,g2,b2; int[] oldPx = new int[w * h]; int[] newPx = new int[w * h]; bitmap.getPixels(oldPx, 0, w, 0, 0, w, h); for(int y = 0; y < h - 1; y++){ for(int x = 0; x < w - 1; x++){ color = oldPx[x+y*w]; r = (color >> 16) & 0xFF; g = (color >> 8) & 0xFF; b = (color >> 0) & 0xFF; int newcolor = oldPx[x+1+y*w]; r1 = (newcolor >> 16) & 0xFF; g1 = (newcolor >> 8) & 0xFF; b1 = (newcolor >> 0) & 0xFF; int newcolor2 = oldPx[x+(y+1)*w]; r2 = (newcolor2 >> 16) & 0xFF; g2 = (newcolor2 >> 8) & 0xFF; b2 = (newcolor2 >> 0) & 0xFF; int tr = (int) (2*Math.sqrt(((r-r1)*(r-r1)+(r-r2)*(r-r2)))); int tg = (int) (2*Math.sqrt(((g-g1)*(g-g1)+(g-g2)*(g-g2)))); int tb = (int) (2*Math.sqrt(((b-b1)*(b-b1)+(b-b2)*(b-b2)))); newPx[x+y*w] = (255 << 24)|(tr << 16)|(tg << 8)|(tb); } } resultBitmap.setPixels(newPx, 0, w, 0, 0, w, h); return resultBitmap; } 對(duì)應(yīng)的效果圖如下:

原圖如下:

挺具有魔幻色彩的。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選