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

Ned Howley
  • 828
  • 11
  • 19
Mub Elme
  • 57
  • 5
  • Could you elaborate how this 2d array relate to A? – Pushan Gupta Aug 03 '17 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... – Serge Ballesta Aug 03 '17 at 11:02
  • 1
    @VidorVistrom If look at 1's, they look like A letter. – Egan Wolf Aug 03 '17 at 11:03

1 Answers1

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.

xander
  • 1,780
  • 9
  • 16
  • ok I have the image as one's and 0's do you know to split it ? – Mub Elme Aug 03 '17 at 12:22
  • 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](https://stackoverflow.com/a/22391906/7462657) 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. :) – xander Aug 03 '17 at 12:39
  • 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 – Mub Elme Aug 03 '17 at 13:16