Java 如何将ARGB转换为RGB字节数组?
我有一个字节数组:Java 如何将ARGB转换为RGB字节数组?,java,rgb,argb,Java,Rgb,Argb,我有一个字节数组: byte[] blue_color = {-1,0,112,-64}; 如何转换成RGB的字节数组 还有,我怎样才能得到颜色的真实RGB值呢?假设它是A组件的第一个元素: byte[] rgb = Arrays.copyOfRange(blue_color, 1, 4); 要获得“真实”颜色值,您需要撤消这两个颜色的补码表示: int x = (int)b & 0xFF; 如何转换成RGB的字节数组 我怎样才能得到颜色的真实RGB值呢 如何将ARGB数组转换为
byte[] blue_color = {-1,0,112,-64};
如何转换成RGB的字节数组
还有,我怎样才能得到颜色的真实RGB值呢?假设它是A组件的第一个元素:
byte[] rgb = Arrays.copyOfRange(blue_color, 1, 4);
要获得“真实”颜色值,您需要撤消这两个颜色的补码表示:
int x = (int)b & 0xFF;
如何转换成RGB的字节数组
我怎样才能得到颜色的真实RGB值呢
如何将ARGB数组转换为RGB
byte[] argb = ...;
byte[] rgb = new byte[(argb.length / 4) * 3];
int index = rgb.length - 1;
for (int i = argb - 1; i >= 0; i -= 4) {
rgb[index--] = argb[i];
rgb[index--] = argb[i - 1];
rgb[index--] = argb[i - 2];
}
如何打印整数值:
byte[] oneColor = {..., ..., ..., ...};
int alpha = oneColor[0] & 0xFF;
int red = oneColor[1] & 0xFF;
int green = oneColor[2] & 0xFF;
int blue = oneColor[3] & 0xFF;
System.out.println("Color: " + alpha + ", " + red + ", " + green ", " + blue);
System.out.println("Hexa color: 0x" + Integer.toHexString(alpha) + " " + Integer.toHexString(red) + " " + Integer.toHexString(green) + " " + Integer.toHexString(blue));
使用
printf
可以做得更漂亮没有copyOfRange方法(我使用java 1.5)@kenny然后使用System.arraycopy()
。当他想跳过一个元素时,如何使用System.arraycopy
?但是这种颜色的rgb实际值是多少?@SulthanSystem.arraycopy(蓝色,1,rgb,0,3)代码>您可能应该了解什么是ARGB,什么是RGB…不,您提出的问题完全不同。对不起,我的意思是将ARGB颜色表示为字节数组,并将其转换为真实的RGB值。什么是真实的RGB值?它们不是。256必须加在负值上。@OliCharlesworth噢,我的意思是+256
;)
byte[] argb = ...;
byte[] rgb = new byte[(argb.length / 4) * 3];
int index = rgb.length - 1;
for (int i = argb - 1; i >= 0; i -= 4) {
rgb[index--] = argb[i];
rgb[index--] = argb[i - 1];
rgb[index--] = argb[i - 2];
}
byte[] oneColor = {..., ..., ..., ...};
int alpha = oneColor[0] & 0xFF;
int red = oneColor[1] & 0xFF;
int green = oneColor[2] & 0xFF;
int blue = oneColor[3] & 0xFF;
System.out.println("Color: " + alpha + ", " + red + ", " + green ", " + blue);
System.out.println("Hexa color: 0x" + Integer.toHexString(alpha) + " " + Integer.toHexString(red) + " " + Integer.toHexString(green) + " " + Integer.toHexString(blue));