[Solved] Retrieve graphical representation of an alphabet letter


Here’s another way that returns Points:

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 output of the above method is:

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),

2

solved Retrieve graphical representation of an alphabet letter