Reputation: 328830
The documentation of BufferedImage is pretty ... terse.
What do the different types mean? What do I get back when I call getPixel() for TYPE_INT_ARGB
? How is it different from what I get back when the type is TYPE_3BYTE_BGR
? What about the other types?
Upvotes: 1
Views: 603
Reputation: 3390
Type represents pixel color type.
Like TYPE_INT_ARGB uses 8 bits for ALPHA component, 8 bits for RED component, 8 bits for GREEN component and 8 bits for BLUE component of color. So pixel color can be stored in int
value.
TYPE_3BYTE_BGR do not store ALPHA component of color. It uses only 3 bytes of int
value.
Like TYPE_USHORT_555_RGB uses 5 bits for each RED, GREEN and BLUE component of color. As it uses 5 bits only, it will have limited number of colors than TYPE_INT_ARGB or TYPE_3BYTE_BGR.
ALPHA component represents how image is transparent.
Likewise other types defines different color schemes.
Upvotes: 2
Reputation: 976
TYPE_INT_ARGB uses Integer to save a color of pixel, like
int color = 0xAARRGGBB,
but 3BYTE_BGR uses
byte[] color = new byte[Blue, Green, Red]
I recommend uses INT_ARGB, you can use alpha, in 3BYTE there are not channel alpha. Integer is faster, than array of byte and easy, for example to get any color use:
(COLOR >> 16) & 0xFF; (24-16 bits are RED).
(COLOR >> 8) & 0xFF; (16- 8 bits are GREEN).
(COLOR >> 0) & 0xFF; ( 8- 0 bits are BLUE).
I always use INT_ARGB or INT_RGB (if I don't need alpha)
Upvotes: 2