[英]Getting pixel colors from Android TextView
我正在尝试获取Android TextView中字体的坐标。
为此,我计划键入TextView,在整个TextView中水平和垂直移动,并查看哪些像素为黑色,哪些像素为白色。 黑色是文本的一部分,白色不是文本的一部分。
您能否告诉我如何在TextView中区分哪些像素是黑色和哪些像素是白色?
谢谢!
我想分享我的想法。 如果您打算迭代textview像素并匹配颜色,则首先需要从textview获取位图。
TextView textview = (TextView) findViewById(R.id.text_title);
textview.setDrawingCacheEnabled(true);
textview.buildDrawingCache();
Bitmap bitmap = textview.getDrawingCache();
之后,您可以通过以下方法简单地检查像素颜色:
for(int x = 1; x <= width; x++)
for(int y = 1; y <= height; y++) {
int pixel = bitmap.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
//now check if black or white color
if(Color.argb(1,redValue, greenValue , blueValue) == Color.BLACK) {
//do work for black pixel
}
else {
//white pixel
}
}
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.