I stumbled upon this code while watching the online development of java games.
Link to video
package gfx; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; public class SpriteSheet { public String path; public int width; public int height; public int[] pixels; public SpriteSheet(String path){ BufferedImage image=null; try { image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path)); } catch (IOException e) { e.printStackTrace(); } if(image==null){ return; } this.path=path; this.width=image.getWidth(); this.height=image.getHeight(); pixels=image.getRGB(0, 0,width,height,null,0,width); for(int i=0;i<pixels.length;i++){ pixels[i] = (pixels[i] & 0xff)/64; } } }
I'm still pretty new to java, so please forgive me if this is obvious. The video shows that
pixels[i] = (pixels[i] & 0xff)
gets rid of the alpha channel in pixel notation 0xAARRGGBB to make it 0xRRGGBB. From what I understand, what 0xff does is to capture the last byte of information from an integer. It is also explained that the number 64 in
pixels[i] = (pixels[i] & 0xff)/64;
obtained by dividing 255 by 4 (I believe this is a limitation on the number of colors).
so essentially my question is: how does 0xff get rid of the alpha channel?
I am quite sure that my confusion is the lack of experience with numbers in hexadecimal form.
source share