Picture Box proportional to original image.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • watashi
    New Member
    • Jul 2007
    • 12

    #1

    Picture Box proportional to original image.

    Hello,

    I have 3 things to consider here, one is source image, form and picture box.

    My picture or image on the form must be proportional in size to the original image.This image on form should be proportional even during resizeing of the form.

    For example if the origianal image is square in shape, my image on form must always be square .

    if original image is rectangle with width > height by 10 times, my image on form ,nothing but

    pictureBox1.siz e.width / picturebox1.hei ght = 10.... even on RESIZING. How to do it.
    I am using C# 2005.

    Thanks in advance.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    There is no property to a picturebox for "keep proportions" or "maintain aspect ration" that I am aware of. You have to do the math yourself, then resize the picture box.

    The way I've done this is to get the aspect ratio of the original image then calculate for the new picturebox size.

    If your original image is 300px wide by 400px tall your ration is 300/400.
    Or 3/4. Or .75 So your width is .75 of your height.

    Now decide if you to lock the width or the height of your picture box, then adjust the other dimension in proportion.

    If your picturebox is 80px tall then you resize the width to (80 * ratio) and you should get a width of 60px

    Put the math and picturebox resize in a function called by the "SizeChange d" event and you should be in business.

    -tlhIn'toq


    Originally posted by watashi
    Hello,

    I have 3 things to consider here, one is source image, form and picture box.

    My picture or image on the form must be proportional in size to the original image.This image on form should be proportional even during resizeing of the form.

    For example if the origianal image is square in shape, my image on form must always be square .

    if original image is rectangle with width > height by 10 times, my image on form ,nothing but

    pictureBox1.siz e.width / picturebox1.hei ght = 10.... even on RESIZING. How to do it.
    I am using C# 2005.

    Thanks in advance.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by watashi
      Hello,

      I have 3 things to consider here, one is source image, form and picture box.

      My picture or image on the form must be proportional in size to the original image.This image on form should be proportional even during resizeing of the form.

      For example if the origianal image is square in shape, my image on form must always be square .

      if original image is rectangle with width > height by 10 times, my image on form ,nothing but

      pictureBox1.siz e.width / picturebox1.hei ght = 10.... even on RESIZING. How to do it.
      I am using C# 2005.

      Thanks in advance.
      Check out this article. I think it describes a solution to what you are looking for.

      -Frinny

      Comment

      • watashi
        New Member
        • Jul 2007
        • 12

        #4
        Hello,
        Thanks for both of you. i did it in tlhintoq's way.
        with regards,

        Comment

        Working...