dcsimg
Results 1 to 5 of 5

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

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    200

    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. #2
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    904

    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. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    200

    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

  4. #4
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    904

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

    Yes.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Posts
    200

    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
  •  



Featured


Click Here to Expand Forum to Full Width