簡體   English   中英

從Android TextView獲取像素顏色

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM