2011-07-18 147 views

回答

2
public Bitmap fudiao(Bitmap bmpOriginal) { 
    int width, height, r,g, b, c,a, gry,c1,a1,r1,g1,b1,red,green,blue; 
    height = bmpOriginal.getHeight(); 
    width = bmpOriginal.getWidth(); 
    int depth = 30; 

     Bitmap bmpSephia = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 
     Canvas canvas = new Canvas(bmpSephia); 
     Paint paint = new Paint(); 
     // ColorMatrix cm = new ColorMatrix(); 
     // cm.setScale(.3f, .3f, .3f, 1.0f); 
     // ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); 
     // paint.setColorFilter(f); 
     canvas.drawBitmap(bmpOriginal, 0, 0, null); 
     for(int y=1; y< height-1; y++) { 
      for(int x=1; x < width-1; x++) { 
       c = bmpOriginal.getPixel(x, y); 

       r = Color.red(c); 
       g = Color.green(c); 
       b = Color.blue(c); 

       c1 = bmpOriginal.getPixel(x-1, y-1); 

       r1 = Color.red(c1); 
       g1 = Color.green(c1); 
       b1 = Color.blue(c1); 


       red = Math.max(67, Math.min(255, Math.abs(r - r1 + 128))); 
       green = Math.max(67, Math.min(255, Math.abs(g - g1 + 128))); 
       blue = Math.max(67, Math.min(255, Math.abs(b - b1 + 128))); 
       if (red > 255) 
       { 
        red = 255; 
       } 
       else if (red < 0) 
       { 
        red = 0; 
       } 

       if (green > 255) 
       { 
        green = 255; 
       } 
       else if (green < 0) 
       { 
        green = 0; 
       } 

       if (blue > 255) 
       { 
        blue = 255; 
       } 
       else if (blue < 0) 
       { 
        blue = 0; 
       } 

       bmpSephia.setPixel(x, y, Color.rgb(red, green, blue)); 
       // bmpSephia.setPixel(x, y, Color.argb(a1, red, green, blue)); 
      } 
     }  
     return bmpSephia; 
    } 

這只是一個浮雕PIC

0
paint.setColorFilter(<LightingColorFilter>); 
+0

你會發現在油漆浮雕,和一堆其他好東西。一旦你玩了一下,這一切都很簡單。 – mbarnes

+0

是的,我已經測試過這個方法,但是藍色效果並不明顯,所以我放棄了這個方法。謝謝 – pengwang