Image sheets with unknown size but known number of cells

I’m new to Corona, so I’m terribly sorry if this is a stupid question :slight_smile:

I’m writing a module for loading a certain type of bitmap fonts. The image file for a font of this type is a sprite sheet with a fixed number of columns and rows (16x14). So my question is, if it’s possible to generate a corona sprite sheet, with graphics.newImageSheet(), where the size of the cells (“width” and “height” in the options table) is unknown but the number of columns and rows are known? Or do I have to load the image first just to get its width and height and divide those with the known number of columns and rows and then reload it as a sprite sheet?

The question is confusing (actually I’m a lazy reader and hate single paragraph posts).

If I read your WOT correctly, you KNOW :

  • Number of columns
  • Number of rows
  • Number of images (no empty cells or known number of filled cells)

DO NOT KNOW :

  • Width or height of image file that contains the cells << CRITICAL PART
  • Width or height of an individual cell

You want to know if you can avoid loading the image in order to measure it. 

I do not believe you can.

You do have to do this to get the width and height:

local tmp = display.newImage( path\_to\_image ) local width = tmp.width local height tmp.height display.remove( tmp ) tmp = nil -- Now you know the width and height of entire image sheet.

After measuring width and height, you can intuit the width and height of cells as long as they are uniform.  However, if there is padding you can’t know how much.

You understood me correctly, thanks for the answer!

I was just hoping there was another way of initializing an image sheet, by sending newImageSheet the number of columns and rows rather than the size of the cells.

The question is confusing (actually I’m a lazy reader and hate single paragraph posts).

If I read your WOT correctly, you KNOW :

  • Number of columns
  • Number of rows
  • Number of images (no empty cells or known number of filled cells)

DO NOT KNOW :

  • Width or height of image file that contains the cells << CRITICAL PART
  • Width or height of an individual cell

You want to know if you can avoid loading the image in order to measure it. 

I do not believe you can.

You do have to do this to get the width and height:

local tmp = display.newImage( path\_to\_image ) local width = tmp.width local height tmp.height display.remove( tmp ) tmp = nil -- Now you know the width and height of entire image sheet.

After measuring width and height, you can intuit the width and height of cells as long as they are uniform.  However, if there is padding you can’t know how much.

You understood me correctly, thanks for the answer!

I was just hoping there was another way of initializing an image sheet, by sending newImageSheet the number of columns and rows rather than the size of the cells.