只有红色值的图像:Android
我们可以只显示红色值的图像吗。这只是为了在图像上看到不同浓度的红色值。任何帮助都是值得的只有红色值的图像:Android,android,image-processing,Android,Image Processing,我们可以只显示红色值的图像吗。这只是为了在图像上看到不同浓度的红色值。任何帮助都是值得的 testButton.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { int redValue = Color.red(bitmap.getPixel(400, 200)); t
testButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v)
{
int redValue = Color.red(bitmap.getPixel(400, 200));
txtData.setText(Integer.toHexString(redValue));
txtData.setTextColor(redValue);
}
});
这是一个示例代码。这里我也得到了红色的值。但最后一行不会执行,因为红色值不是颜色…因此完全透明。但是有没有办法这样呢
我们可以操纵这个值,我们可以在红色中看到这个值,类可能具有实现所需的所有方法
txtData.setTextColor(Color.argb(0xFF,redValue,0,0));
试试这个
public static Bitmap getRedComponentBitmap(Bitmap source) {
Bitmap bitmap = Bitmap.createBitmap(source.getWidth(),source.getHeight(), Bitmap.Config.ARGB_8888);
for (int i = 0; i < source.getWidth(); i++) {
for (int j = 0; j < source.getHeight(); j++) {
int pixel = source.getPixel(i, j);
// get red color value
int red = Color.red(pixel);
int color = Color.argb(0xFF, red, 0, 0);
bitmap.setPixel(i, j, color);
}
}
return bitmap;
}
公共静态位图getRedComponentBitmap(位图源){
位图Bitmap=Bitmap.createBitmap(source.getWidth()、source.getHeight()、Bitmap.Config.ARGB_8888);
for(int i=0;i
我建议在非UI线程中使用此方法。是否有代码exampletxtData.setTextColor(Color.argb(0xFF,redValue,0,0));在使用这一行时,我得到了相同的结果…显示红色值,但不可见。@user3040168此处的redValue的post值在hexvalue…bd中。。十进制返回189,然后txtData.setTextColor(Color.argb(0xFF,0xBD,0,0))对我有效。文本是可见的是它是可见的…它起作用了是我的错误一行被错误地命令了…但是你能告诉我为什么这个透明度变差了…是因为我们提供了alpha值…可能是