Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active March 10, 2019 12:16
Show Gist options
  • Save ezhov-da/88ddf3ce4cf8151861f56eb80703202b to your computer and use it in GitHub Desktop.
Save ezhov-da/88ddf3ce4cf8151861f56eb80703202b to your computer and use it in GitHub Desktop.
convert integer to rgb
int blue = 0x0000ff & rgb;
int green = 0x0000ff & (rgb >> 8) ;
int red = 0x0000ff & (rgb >> 16) ;
int alpha = 0x0000ff & (rgb >> 24) ;
//We can get this information natively from the raster with this:
byte[] pixels = ((DataBufferByte) img. getRaster() . getDataBuffer() ) . getData() ;
for (int i = 0; i < pixels. length / 3 ; i++) {
int blue = Byte. toUnsignedInt(pixels[3*i] ) ;
int green = Byte. toUnsignedInt(pixels[3*i+1] ) ;
int red = Byte. toUnsignedInt(pixels[3*i+2] ) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment