アンドロイドには、私の空間的な表現(例えば 'A')が表示されます。点の配列やパスオブジェクトやベクトルのようなもの。私はcanvas.drawText()を使用する代わりに、自分自身で画面に文字を描画します。これは可能ですか?アルファベット文字の図式表現を取得する
-5
A
答えて
1
ここでポイントを返し、別の方法です:
private void textStuff() {
int textSize = 32;
char letter = 'A';
getPointsForChar(textSize, letter);
}
@NonNull
private ArrayList<Point> getPointsForChar(int textSize, char letter) {
Canvas canvas = new Canvas();
Paint paint = new Paint();
Bitmap bitmap = Bitmap.createBitmap((int) (float) textSize, (int) (float) textSize, Bitmap.Config.ALPHA_8);
canvas.drawPaint(paint);
canvas.setBitmap(bitmap);
paint.setColor(Color.BLACK);
paint.setTextSize(textSize);
canvas.drawText(String.valueOf(letter), 0, (float) textSize, paint);
Log.d("Font", "bitmap " + bitmap.toString());
ArrayList<Point> points = new ArrayList<>();
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
int pixel = bitmap.getPixel(x, y);
if (pixel != Color.TRANSPARENT) {
points.add(new Point(x, y));
}
}
}
StringBuilder stringBuilder = new StringBuilder("The following points make up '" + letter + "':");
for (Point point : points) {
stringBuilder.append("\n\t").append(point.toString()).append(", ");
}
Log.d("Font", stringBuilder.toString());
return points;
}
上記の方法の出力は次のとおりです。
The following points make up 'A':
Point(1, 29),
Point(1, 30),
Point(1, 31),
Point(2, 27),
Point(2, 28),
Point(2, 29),
Point(2, 30),
Point(2, 31),
Point(3, 24),
Point(3, 25),
Point(3, 26),
Point(3, 27),
Point(3, 28),
Point(3, 29),
Point(3, 30),
Point(3, 31),
Point(4, 22),
Point(4, 23),
Point(4, 24),
Point(4, 25),
Point(4, 26),
Point(4, 27),
Point(4, 28),
Point(5, 19),
Point(5, 20),
Point(5, 21),
Point(5, 22),
Point(5, 23),
Point(5, 24),
Point(5, 25),
Point(5, 26),
Point(6, 17),
Point(6, 18),
Point(6, 19),
Point(6, 20),
Point(6, 21),
Point(6, 22),
Point(6, 23),
Point(6, 24),
Point(6, 25),
Point(7, 14),
Point(7, 15),
Point(7, 16),
Point(7, 17),
Point(7, 18),
Point(7, 19),
Point(7, 20),
Point(7, 21),
Point(7, 24),
Point(7, 25),
Point(8, 12),
Point(8, 13),
Point(8, 14),
Point(8, 15),
Point(8, 16),
Point(8, 17),
Point(8, 18),
Point(8, 24),
Point(8, 25),
Point(9, 10),
Point(9, 11),
Point(9, 12),
Point(9, 13),
Point(9, 14),
Point(9, 15),
Point(9, 24),
Point(9, 25),
Point(10, 10),
Point(10, 11),
Point(10, 12),
Point(10, 13),
Point(10, 24),
Point(10, 25),
Point(11, 10),
Point(11, 11),
Point(11, 12),
Point(11, 13),
Point(11, 14),
Point(11, 15),
Point(11, 24),
Point(11, 25),
Point(12, 12),
Point(12, 13),
Point(12, 14),
Point(12, 15),
Point(12, 16),
Point(12, 17),
Point(12, 18),
Point(12, 24),
Point(12, 25),
Point(13, 14),
Point(13, 15),
Point(13, 16),
Point(13, 17),
Point(13, 18),
Point(13, 19),
Point(13, 20),
Point(13, 21),
Point(13, 24),
Point(13, 25),
Point(14, 17),
Point(14, 18),
Point(14, 19),
Point(14, 20),
Point(14, 21),
Point(14, 22),
Point(14, 23),
Point(14, 24),
Point(14, 25),
Point(15, 19),
Point(15, 20),
Point(15, 21),
Point(15, 22),
Point(15, 23),
Point(15, 24),
Point(15, 25),
Point(15, 26),
Point(16, 22),
Point(16, 23),
Point(16, 24),
Point(16, 25),
Point(16, 26),
Point(16, 27),
Point(16, 28),
Point(16, 29),
Point(17, 24),
Point(17, 25),
Point(17, 26),
Point(17, 27),
Point(17, 28),
Point(17, 29),
Point(17, 30),
Point(17, 31),
Point(18, 27),
Point(18, 28),
Point(18, 29),
Point(18, 30),
Point(18, 31),
Point(19, 30),
Point(19, 31),
+0
ねえジョナサンこれは私が必要とする正確な結果です、ありがとうございます。これらの値を取得する他の方法はありますか?よりパフォーマンスに優れた方法。たとえば、アンドロイドシステムがテキストをどのように描画するのか知っていますか? drawTextに "asd"と入力すると、 "asd"の物理的表現をどのように知ることができますか? – user6650650
+0
私の研究では、アンドロイドシステムは通常、ネイティブメソッド(Javaではなく)を使用してテキストを描画することが判明しましたが、これはパフォーマンス上の理由からです。 – Jon
0
Path
は、次のコードを使用して取得できます。私はまだこのコードによって生成されたパスがネイティブパスであり、というではないので、より有用なパスを得る方法があるかどうかを調べようとしています。
Path path = new Path();
Paint paint = new Paint();
paint.getTextPath("A", 0, 1, 0f, 0f, path);
関連する問題
- 1. キリル文字アルファベットの正規表現
- 2. 正規表現最後の文字をアルファベットで検索する
- 3. 文字の次のアルファベットを取得する
- 4. アルファベットの文字とスペースのJavascript正規表現ですか?
- 5. 正規表現に文字が到達するまでの文字列を取得する正規表現
- 6. JComboBoxの項目を取得する文字列の表現
- 7. 特殊文字(:)と数字とアルファベットのみを許可する正規表現
- 8. MultipartFormDataContentの文字列表現を取得する方法
- 9. mongoose:クエリの文字列表現を取得する方法
- 10. SQL DateTimeの文字列表現を取得する
- 11. XMLノードの文字列表現を取得する
- 12. 文字列の配列を取得する正規表現
- 13. 文字列の整数表現を取得する方法
- 14. SecKeyの文字列表現を取得する
- 15. アルファベット1文字以上の特殊文字を持つ正規表現
- 16. 分割文字列のアルファベットは、正規表現のPython
- 17. C#:スカンジナビア語のアルファベットの文字を取得しますか?
- 18. 正規表現パターンからサブ文字列を取得する
- 19. 文字列からlat/lngを取得する正規表現
- 20. アルファベット順の高い文字列を取得
- 21. txtファイルからのアルファベット文字の出現をカウントする
- 22. 正規表現は文字列の一部を取得
- 23. 正規表現とアルファベットと数字の順不同の文字列
- 24. セルから文字列値を取り出し、その文字をアルファベット順にソートする数式
- 25. 正規表現を使用してアルファベット文字列から特定の文字を削除する方法
- 26. Spring SpELのMongoDB正規表現文字をエスケープする - SpelParseExceptionを取得する
- 27. アルファベット以外の文字を空白で置き換える正規表現
- 28. SQL - 数字の数値だけを取得し、アルファベットと文字ではない列から取得する
- 29. CDbCriteriaからの文字列表現の取得
- 30. Dateオブジェクトの文字列表現をWatch式ウィンドウに表示
あなたは数学的表現とはどういう意味ですか?キャラクターのアスキーな価値を得ることを意味しましたか? –
もっと具体的になりますか?何をしたいですか?どこに文字を描く必要がありますか? – BlueMango
@AbdulWaheed私は、OPがニューラルネットワーク用のトレーニングセット(OCRを実装したいと思うかもしれない)のようなものを望んでいると思います。 –