Making image darker

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Making image darker

Postby sandis84 » Tue Sep 08, 2009 10:38 am

So I want a image to become darker when selected. It feels as if this should be easy, but I cant find an easy way. I guess I could put them in front of a dark layout and override the layouts getChildStaticTransformation to make the image transparent and thus darker... but it feels overkill, and I almost doubt that it would be faster then to simply have another slightly darker image. How would you guys do?
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Top

Postby qlimax » Tue Sep 15, 2009 2:48 pm

hi sandis!


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public Bitmap convert(Bitmap source) {
  2.  
  3.  
  4.  
  5.                    
  6.  
  7.                 ColorMatrix cm = new ColorMatrix();
  8.  
  9.             //  cm.setSaturation(0);  //that's for grayscale
  10.  
  11.                 cm.getArray()[4]=-50;
  12.  
  13.                 cm.getArray()[9]=-50;
  14.  
  15.                 cm.getArray()[14]=-50;
  16.  
  17.                
  18.  
  19.                 ColorMatrixColorFilter cmcf = new ColorMatrixColorFilter(cm);
  20.  
  21.                
  22.  
  23.                 Paint p = new Paint();
  24.  
  25.                 p.setColorFilter(cmcf);
  26.  
  27.                
  28.  
  29.                
  30.  
  31.                
  32.  
  33.                 Bitmap converted = Bitmap.createBitmap(
  34.  
  35.                             source.getWidth(), source.getHeight(),
  36.  
  37.                             Bitmap.Config.RGB_565);
  38.  
  39.                 Canvas c = new Canvas(converted);
  40.  
  41.                 c.drawBitmap(source, 0, 0, p);
  42.  
  43.                 return converted;
  44.  
  45.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


http://developer.android.com/reference/ ... atrix.html

you can change the value -50 as your preference, or to positive values to get more luminose images.
hope that helps.. let me know :)

Bye.
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby qlimax » Thu Oct 01, 2009 5:18 pm

a bad habit of this forum is to never say thank you ... :!:
imho
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby sandis84 » Fri Oct 02, 2009 10:16 am

lol you are right. Sorry mate, and thanks for the help. =)
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Postby qlimax » Fri Oct 02, 2009 11:46 am

big up :D
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 3 guests