
Oct 3rd, 2019, 07:00 PM
#1
Thread Starter
Addicted Member
[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.
Last edited by Ordinary Guy; Oct 3rd, 2019 at 07:04 PM.

Oct 4th, 2019, 06:13 AM
#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!
Last edited by SamOscarBrown; Oct 4th, 2019 at 06:26 AM.

Oct 4th, 2019, 06:56 AM
#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

Oct 4th, 2019, 07:37 AM
#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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete

Oct 4th, 2019, 07:42 AM
#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
Last edited by passel; Oct 4th, 2019 at 07:47 AM.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

Oct 4th, 2019, 11:09 AM
#6
Thread Starter
Addicted Member
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
Thanks Arnoutdv for your code answer. Thanks everyone else too.
BTW: it's Sqr, not Sqrt

Oct 4th, 2019, 04:06 PM
#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.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
