Posted By

whitetiger on 11/09/06


Tagged

image jpg java filter images Converter RGB j2me gray JAI dilate bit planes


Versions (?)

Java - showBitPlanes


 / Published in: Java
 

  1. public BufferedImage showBitPlanes(BufferedImage bi, int lv)
  2. {
  3. int level = 0;
  4.  
  5. switch(level)
  6. {
  7. case 0:
  8. level = 128;
  9. break;
  10. case 1:
  11. level = 64;
  12. break;
  13. case 2:
  14. level = 32;
  15. break;
  16. case 3:
  17. level = 16;
  18. break;
  19. case 4:
  20. level = 8;
  21. break;
  22. case 5:
  23. level = 4;
  24. break;
  25. case 6:
  26. level = 2;
  27. break;
  28. case 7:
  29. level = 1;
  30. break;
  31. default:
  32. return null;
  33. }
  34.  
  35. int width = bi.getWidth();
  36. int height = bi.getHeight();
  37.  
  38. BufferedImage img = new BufferedImage(width, height, bi.getType());
  39.  
  40. for(int x=0; x<width; x++)
  41. for(int y=0; y<height; y++)
  42. img.setRGB(x, y, ((bi.getRGB(x, y) & level)/level)*255);
  43.  
  44. return img;
  45. }

Report this snippet  

You need to login to post a comment.