# Thread: Comparing the size of Picture1 with the sizes of Picture2, Picture3, and Picture4

1. ## Comparing the size of Picture1 with the sizes of Picture2, Picture3, and Picture4

I have 4 Pictureboxes, Picture1, 2, 3,and 4. I need to know which Picturebox of 2, 3, and 4 is the closest in overall size to Picture1

For example:

Picture1 is 663w x 516h

Picture2 is 658w x 526h

Picture3 is 682w x 511h

Picture4 is 688w x 481h

I know by looking at the size of each Picturebox, Picture2 is the closest to Picture1

I used the area size of each Picture and picked the smallest results and I got Picture2 as the answer but I am not sure this will work in all cases

How would you go about determining this code wise

2. ## Re: Comparing the size of Picture1 with the sizes of Picture2, Picture3, and Picture4

Assuming you are simply multiplying w*h, that would mean that an image that is 171054w x 2h would be "equal" to Picture1 since their areas are equal; but that would clearly be a wrong answer visually.

My initial thought would be to do it this way:

Calculate dw as abs(pic1.width - picN.width)
Calculate dh as abs(pic1.height - picN.height)

Then calculate:

dA = dw*pic1.height + dh*pic1.width + dw*dh

and whatever picturebox minimizes dA would be "closest"

3. ## Re: Comparing the size of Picture1 with the sizes of Picture2, Picture3, and Picture4

Is this what you mean

Dim dw As Long, dh As Long, dA As Long

dw = Abs(Picture1.Width - Picture2.Width)
dh = Abs(Picture1.Height - Picture2.Height)
dA = dw * Picture1.Height + dh * Picture1.Width + dw * dh 'dA = 9260

dw = Abs(Picture1.Width - Picture3.Width)
dh = Abs(Picture1.Height - Picture3.Height)
dA = dw * Picture1.Height + dh * Picture1.Width + dw * dh 'dA = 13214

dw = Abs(Picture1.Width - Picture4.Width)
dh = Abs(Picture1.Height - Picture4.Height)
dA = dw * Picture1.Height + dh * Picture1.Width + dw * dh 'dA = 36980

I would pick the 1st example of 9260

Yes.

5. ## Re: Comparing the size of Picture1 with the sizes of Picture2, Picture3, and Picture4

Thank you, very appreciated

#### Posting Permissions

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

Click Here to Expand Forum to Full Width
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}