yoga1290

get Image RGB

Oct 17th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. /*
  2.   I used this in my OpenGL project , to decode external images & save it as RGB array inside a certain node
  3. */
  4. private void assignImage(node n,String src)
  5.     {
  6.         try{
  7.             BufferedImage img=ImageIO.read(new File(src));
  8.             int i,j,r,g,b,rgb;
  9.             n.h=img.getHeight();
  10.             n.w=img.getWidth();
  11.             n.RGB=new int[n.w][n.h][3];
  12.            
  13. //            int andr=Integer.parseInt("111111110000000000000000",2);
  14. //            int andg=Integer.parseInt("000000001111111100000000",2);
  15. //            int andb=Integer.parseInt("000000000000000011111111",2);
  16.             Color c;
  17.             for( i=0;i<n.w;i++)
  18.                 for( j=n.h-1;j>=0;j--)
  19.                 {
  20.                      rgb=img.getRGB(i, j);
  21.                      c=new Color(rgb);
  22.                      n.RGB[i][j][0]=c.getRed();
  23.                      n.RGB[i][j][1]=c.getGreen();
  24.                      n.RGB[i][j][2]=c.getBlue();
  25.                      
  26. //                    r= ((rgb & andr )>>16);
  27. //                    g= ((rgb & andg )>>8);
  28. //                    b= (rgb & andb );
  29.                 }
  30.         }catch(Exception e){}      
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment