android圖片特效處理之懷舊效果

來源:互聯網
上載者:User

標籤:知識   boa   特效   number   sof   toc   too   知識庫   結構   

圖片特效處理系列將介紹圖片的像素點的特效處理,這些物資注重的是原理。也就是說只要你知道這些演算法不管是C++,VB,C#,Java都可以做出相同的特效。下面將介紹圖片懷舊效果的演算法。演算法如下:


上面公式的意思是說將每個像素點的RGB值先分離出來,然後再按照上面的三個算式分別重新計算出RGB值然後做為當前點的RGB值。

下面看片:

原圖片:


處理後:



代碼:

 

[java] view plain copy
  1. /** 
  2.      * 懷舊效果(相對之前做了最佳化快一倍) 
  3.      * @param bmp 
  4.      * @return 
  5.      */  
  6.     private Bitmap oldRemeber(Bitmap bmp)  
  7.     {  
  8.         // 速度測試  
  9.         long start = System.currentTimeMillis();  
  10.         int width = bmp.getWidth();  
  11.         int height = bmp.getHeight();  
  12.         Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);  
  13.         int pixColor = 0;  
  14.         int pixR = 0;  
  15.         int pixG = 0;  
  16.         int pixB = 0;  
  17.         int newR = 0;  
  18.         int newG = 0;  
  19.         int newB = 0;  
  20.         int[] pixels = new int[width * height];  
  21.         bmp.getPixels(pixels, 0, width, 0, 0, width, height);  
  22.         for (int i = 0; i < height; i++)  
  23.         {  
  24.             for (int k = 0; k < width; k++)  
  25.             {  
  26.                 pixColor = pixels[width * i + k];  
  27.                 pixR = Color.red(pixColor);  
  28.                 pixG = Color.green(pixColor);  
  29.                 pixB = Color.blue(pixColor);  
  30.                 newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);  
  31.                 newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);  
  32.                 newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);  
  33.                 int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG, newB > 255 ? 255 : newB);  
  34.                 pixels[width * i + k] = newColor;  
  35.             }  
  36.         }  
  37.           
  38.         bitmap.setPixels(pixels, 0, width, 0, 0, width, height);  
  39.         long end = System.currentTimeMillis();  
  40.         Log.d("may", "used time="+(end - start));  
  41.         return bitmap;  
  42.     }  


上面的代碼是最佳化了的,也就是用到了這篇android影像處理系列之六--給圖片添加邊框(下)-圖片疊加裡面所說的getPixels()和setPixels()。自己簡單的測試了一下,速度比原來getPixel()和setPixel()速度快了一倍。

android圖片特效處理之懷舊效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.