私は自分の考えを伝えたいと思います。テキストビューのピクセルを繰り返して色を一致させる場合は、まず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
}
}
はそれがお役に立てば幸いです。
Androidはコード内のシンボルの幅と高さを認識していません。これらの変数の使い方を教えてください。 – Eddev
幅と高さの変数はそれぞれTextviewの幅と高さを表します。適切な関数呼び出しで置き換えてください – NightFury
ありがとうございます。私はtextview.getWidth()とgetHeight()を使ってみましたが、これは0を返します。もう一つは、Bitmapであるtextview.getDrawingCache()がnullのBitmapオブジェクトを返すことです。これをどうすれば解決できますか? – Eddev