如何在黑莓中实现按位颜色编码
我是黑莓的新手。目前我正在研究位图颜色编码
我为更改图像颜色而实现的代码如下: 位图 greyScale = new Bitmap(original.getWidth(),original.getHeight());
int[] argb = new int[original.getWidth() * original.getHeight()];
original.getARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
for (int i = argb.length - 1; i >= 0; --i)
{ int alpha = argb[i]>>> 24; int red = argb[i] >>> 16& 0xFF; int green = argb[i] >>> 8& 0xFF; int 蓝色 = 255-argb[i] & 0xFF;
int grey = (int) (0.3 * red + 0.59 * green + 0.11 * blue);
int red2 = red * contrast/10+brightness;
if (red2>0xFF) red2 = 0xFF;
if (red2<0) red2 = 0;
int green2 = green * contrast/10+brightness;
if (green2>0xFF) green2 = 0xFF;
if (green2<0) green2 = 0;
int blue2 = blue * contrast/10+brightness;
if (blue2>0xFF) blue2 = 0xFF;
if (blue2<0) blue2 = 0;
int composite = (alpha << 24) | (red2 << 16) | (green2 << 8) | blue2|red|green;
argb[i] = composite;
}
greyScale.setARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
return greyScale;
}
我能够实现这种方法并且也能够获得各种颜色。 但任何人都可以帮助我了解 Argb 如何处理整个颜色代码。
问候 平克什·古普塔
i am new to blackberry.Currently i am working upon bitmap color coding
The code which i am implement for changing colors of image are as follows:
Bitmap greyScale = new Bitmap(original.getWidth(), original.getHeight());
int[] argb = new int[original.getWidth() * original.getHeight()];
original.getARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
for (int i = argb.length - 1; i >= 0; --i)
{
int alpha = argb[i] >> 24;
int red = argb[i] >> 16 & 0xFF;
int green = argb[i] >> 8 & 0xFF;
int blue = 255-argb[i] & 0xFF;
int grey = (int) (0.3 * red + 0.59 * green + 0.11 * blue);
int red2 = red * contrast/10+brightness;
if (red2>0xFF) red2 = 0xFF;
if (red2<0) red2 = 0;
int green2 = green * contrast/10+brightness;
if (green2>0xFF) green2 = 0xFF;
if (green2<0) green2 = 0;
int blue2 = blue * contrast/10+brightness;
if (blue2>0xFF) blue2 = 0xFF;
if (blue2<0) blue2 = 0;
int composite = (alpha << 24) | (red2 << 16) | (green2 << 8) | blue2|red|green;
argb[i] = composite;
}
greyScale.setARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());
return greyScale;
}
I am capable of implementing this method and capable of obtaining various colors also.
But can anyone help me that how Argb is working on the entire code for colors.
regards
Pinkesh Gupta
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢,我正在使用您的代码并进行一些修改。为了回答你的问题,
argb中的每个字节都是一个32位值,代表0xAARRGGBB格式中的一个像素:
所以0xFFFFFFFF将是不透明的白色的。
提取值的代码的工作原理如下:
要获得 apha 值,请将所有内容右移 24 位,仅保留前 8 位。
要获得红色,请右移 16 位,保留前 16 位。然后使用 AND 运算符清空前 8 位。这留下了第二个 8 位
对于绿色,移动 8 位并空白前 16 位,留下第三个 8 位
最后对于蓝色,只需空白前 24 位
此时,您可以更改 alpha,红色,绿色和蓝色值。我正在使用
获取位图的灰度版本。
最后,要组成一个新值,将每个部分移动到正确的位置并叠加它们(这恰好与本例中添加它们相同)
然后设置 argb[i] = newval 来替换像素。
Thanks, I am using your code with some modifications. To answer your question,
Each byte in argb is a 32-bit value representing one pixel in 0xAARRGGBB format:
So 0xFFFFFFFF would be opaque white.
The code to extract the values works as follows:
To get the apha value, shift everything right by 24 places leaving only the first 8 bits
To get red, shift right by 16, leaving the top 16 bits. Then blank out the top 8 bits using the AND operator. This leaves the second 8 bits
For green, shift by 8 bits and blank out first 16 bits, leaving the third 8 bits
And finally for blue, just blank out the top 24 bits
At this point you can make changes to the alpha,red,green and blue values. I am using
To get a grayscale version of the bitmap.
Finally, to make up a new value, shift every part to the correct place and superimpose them (which happens to be the same as adding them in this case)
Then set
argb[i] = newval
to replace the pixel.