Results 1 to 6 of 6

Thread: resizing bitmaps to fit the picture box

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5

    resizing bitmaps to fit the picture box

    Is it possible to resize the bitmaps to fit the fixed size of the picture box without having to manually resize every bmp.
    Thanks

  2. #2
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    You can use an Image box to stretch a picture to fit any size you want, but you will need to know what the aspect ratio is of the original picture. It helps to load the picture into a hidden picturebox, then record the aspect ratio, set the image box to the same ratio with the stretch property set to true, then finally copy the image from the hidden PictureBox to the ImageBox, and it will show up as big or small as you want.

    Code:
    Private Sub Form_Load()
      Dim PictureAspectRatio As Double
      Picture1.Visible = False
      Picture1.AutoSize = True
      Picture1.Picture = LoadPicture("C:\WINDOWS\Desktop\TestImage.jpg")
      PictureAspectRatio = Picture1.Width / Picture1.Height
      
      Image1.Stretch = True
      Image1.Width = Image1.Height * PictureAspectRatio
      Image1.Picture = Picture1.Picture
    End Sub
    If you really need the picture to end up in a PictureBox control, then you can use the PaintPicture method to scale the image.
    ----------

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5

    Thanks

    Thank you

  4. #4
    Megatron
    Guest
    If you do not want to use an additional Image, you could use the PaintPicture method.
    Code:
    Picture2.PaintPicture picSource, 0, 0, Picture2.Width, Picture2.Height

  5. #5
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Set the picture box's AutoSize property to True:

    Private Sub Form_Load()
    Picture1.AutoSize = True
    End Sub

    or do it with an Image instead (works better):

    Private Sub Form_Load()
    Image1.Stretch = True
    End Sub
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  6. #6
    gaffa
    Guest
    The AutoSize proeprty changes the size of the picturebox to match the bitmpa size, not the other way around.

    - gaffa

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