2

Hi Everyone i'm trying to fill 2d arrays in java with 0's and 1's. The 1's will represent white and 0 represent black. I would like to have one 2d array for every char in alphabet a to z example:

    String[][] myArray = {//letter A
    {"0", "0", "1", "0", "0"},
    {"0", "1", "0", "1", "0"},
    {"1", "1", "1", "1", "1"},
    {"1", "0", "0", "0", "1"},
    {"1", "0", "0", "0", "1"},};

is there a quick way to do it. my 2d array need to be 22 by 16

3
  • Could you elaborate how this 2d array relate to A? Commented Aug 3, 2017 at 10:58
  • This will give in the end a fixed size raster font. There can be caveats when first dealing with fonts, so you really should study how they work. For example, because of letters like jg the baseline is not the bottom line. And you should wonder whether the horizontal and vertical spacings or included in the 16x22 matrix... Commented Aug 3, 2017 at 11:02
  • 1
    @VidorVistrom If look at 1's, they look like A letter. Commented Aug 3, 2017 at 11:03

1 Answer 1

1

You could develop a small editor to "draw" the pixels and convert them to ASCII code or just use any available ASCII or pixel font and convert it to your format.

I mean if you take a simple tile based font image like this

tile based pixel font

and extract the pixel information and convert them to your array format, that would be quicker. Since the characters have a fixed size you can get a specific character range from an image like that pretty easily, all you need is to load the image and read the 2d pixel information, but that should be faily easy with a few lines of Java code.

Sign up to request clarification or add additional context in comments.

3 Comments

ok I have the image as one's and 0's do you know to split it ?
well you just have to figure out where the letters are you need, and then how large one "tile" is to iterate through it with a loop. so if I open the image with MS Paint and zoom in you can see the pixel coordinates in the bottom left corner. To actually read the color at the pixel coordinate you can use this example and modify it to only return if the pixel is black or white. It should not be that hard and it's better if you figure it out yourself instead of just using code someone else writes. :)
I've managed to get 0's and 1's for font image into a txt file and imported into a 2d array, which i'll need to split into smaller 2d array's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.