# Thread: [RESOLVED] How to determine the number of rows, columns, and size

1. ## [RESOLVED] How to determine the number of rows, columns, and size

If I know the number of squares and I know that all squares are the same size how can I figure out the number of rows, columns, and the size of the squares if I also know the width and height of a picture.

I have several bitmap pictures in a folder that my app will load based on user input. All bitmaps are a matrix of nn rows and nn columns of squares of the same size. Now the very last pixel in the picture (Picture1.Width - 1, Picture1.Height - 1) is a color that tells me the number of squares. For example the last pixel has a color code of RGB(230,0,0) or just plain 230. So this tells me that there are 231 squares (0 - 230) in the matrix of this picture. Knowing this and the width and height how do I calculate the number or rows, columns, and the size of the squares.  Reply With Quote

2. ## Re: How to determine the number of rows, columns, and size

MANY years ago, I could have told you how (I was an Engineer Major in college) as I took every conceivable math class there was....but NOW? Not able to. Now, IF the picture were a SQUARE, it would be as easy as finding the square root of that number (231)...of course, that is slightly over 25 (Squared is 225), so that would indicate there were 25 rows and 25 columns and your RGB should be (224,0,0). Then, the calculation for the size of each square is 1/25th of the height (or width) of the square picture. But, as your picture may not be square, I am unable to think that hard any more. Maybe a math major could give you the formula in a heartbeat!  Reply With Quote

3. ## Re: How to determine the number of rows, columns, and size

Isn't it as simple as:
Size square = Sqrt((Width * Height) / #Squares)
Rows = Height / Size square
Columns = Width / Size square  Reply With Quote

4. ## Re: How to determine the number of rows, columns, and size

does it say anywhere that the number of rows and columns would be equal, unless all # of squares would have to be a square, what proportion of rows to columns, i am sure there is not enough information for a useful response

231 squares could be in any of the below grids, but not a square grid
3 x 77 7 x 33 11 x 21 21 x 11 33 x 7 77 x 3  Reply With Quote

5. ## Re: How to determine the number of rows, columns, and size

But if you used an example, and applied Arnoutdv's code, you should get the answer, e.g.
Try an image that is 2100 pixels by 1100 pixels and has 231 squares.

Run it through the code and of course you get a result of 21 columns by 11 rows of 100x100 tiles.

The ratio of the pixels has to match the ratio of the rows and columns, and since you know the number of pixels in the first, you can figure out the number of pixels in the second.

The area of the picture in units of pixels has to match the area of the picture in units of tiles  Reply With Quote

6. ## Re: How to determine the number of rows, columns, and size

I applied Arnoutdv's code to a picture that I knew all the results

Code:
```  '
'
txtSize.Text = CInt(Sqr((Picture1.Width * Picture1.Height) / Picture1.Point(Picture1.Width - 1, Picture1.Height - 1) + 1))
Text1.Text = CInt(Picture1.Height / CInt(txtSize.Text))
Text2.Text = CInt(Picture1.Width / CInt(txtSize.Text))
'
'```
txtSize = "44"
Text1.Text = "11"
Text1.Text = "21"

These values are correct

BTW: it's Sqr, not Sqrt  Reply With Quote

7. ## Re: How to determine the number of rows, columns, and size

I assumed Arnoutdv didn't give you actual code but a description of the logic, i.e. pseudo code. It just happened to be very close to the real code.

I mean "Size Square" is not a valid variable, and "#Squares" isn't either.
I hope you didn't think that Sqrt would be the function name since none of the other "code" was real.
Someone not familiar with the language might think Sqr meant Square not Square root, so the pseudo code was being more descriptive to be clear.

As a long time user of legacy VB you would know to translate Sqrt to Sqr and a C programmer would know to change it to sqrt and a VB.Net programmer would use Math.Sqrt, or Sqrt if they already imported the Math namespace.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•