Advertisement
CPU_Terminator

ARGB Byte Array to BufferedImage

Jan 5th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public BufferedImage ARGBByteToBufferedImage(byte[] imgBuff, int w, int h){
  2.     BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  3.  
  4.     int[] ARGB_Data = new int[w * h];
  5.    
  6.     for(int i = 0, k = 0; i < ARGB_Data.length; i++, k = k + 4){
  7.         int A = (imgBuff[k]     << 24) & 0xFF000000;
  8.         int R = (imgBuff[k + 1] << 16) & 0x00FF0000;
  9.         int G = (imgBuff[k + 2] <<  8) & 0x0000FF00;
  10.         int B = (imgBuff[k + 3])       & 0x000000FF;
  11.  
  12.         ARGB_Data[i] = A | R | G | B;
  13.     }
  14.  
  15.     img.setRGB(0, 0, w, h, ARGB_Data, 0, w);
  16.  
  17.     return img;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement