Last active
March 10, 2019 12:16
-
-
Save ezhov-da/88ddf3ce4cf8151861f56eb80703202b to your computer and use it in GitHub Desktop.
convert integer to rgb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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