Results 1 to 7 of 7

Thread: Picture Sizing to fit screen

  1. #1
    Guest

    Question

    I have various picture sizes 800x600, 640x480... is there a way to shrink and expand them automatically to fit the image box I create on a form?

  2. #2
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Size your image box and set STRETCH property to true

    DocZaf
    {;->

  3. #3
    Guest
    If i set it to stretch some o fthe thinner pics lok very distorted? Can I stretch it to fit the box, center the picture in the box, and keep it porportional to the box that it is in?

  4. #4
    Lively Member
    Join Date
    May 1999
    Posts
    100
    Hi. You can look at this code. Make a form and a imagebox in it. You can now resize the form but the propotions are right.


    Private Sub Form_Resize()
    Image1.Width = Me.ScaleWidth
    Image1.Height = Me.ScaleHeight
    ScaleImage
    End Sub

    Public Sub ScaleImage()
    Dim intDelen, intDelen2
    If Image1.Picture.Width = 0 And Image1.Picture.Height = 0 Then Exit Sub
    intDelen = 0
    intDelen2 = 0

    If Me.ScaleWidth < (Image1.Picture.Width / 2) Or Me.ScaleHeight < (Image1.Picture.Height / 2) Then
    intDelen = ((Image1.Picture.Width / 2) - Me.ScaleWidth) / (Image1.Picture.Width / 2)
    intDelen2 = ((Image1.Picture.Height / 2) - Me.ScaleHeight) / (Image1.Picture.Height / 2)
    If intDelen >= intDelen2 Then
    Image1.Width = (Image1.Picture.Width / 2) * (1 - intDelen)
    Image1.Height = (Image1.Picture.Height / 2) * (1 - intDelen)
    Else
    Image1.Height = (Image1.Picture.Height / 2) * (1 - intDelen2)
    Image1.Width = (Image1.Picture.Width / 2) * (1 - intDelen2)
    End If
    Else
    Image1.Width = (Image1.Picture.Width / 2)
    Image1.Height = (Image1.Picture.Height / 2)
    End If
    Image1.Top = (frmImage.ScaleHeight / 2) - (Image1.Height / 2)
    Image1.Left = (frmImage.ScaleWidth / 2) - (Image1.Width / 2)
    End Sub

  5. #5
    Guest
    thanks for the code, is there any way that it can be modified so that it automatically sizes the picture to fit in the screen, and the user does not have the ability to resize the screen.

  6. #6
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554

    This is one way


    It might not be the shortest number of code lines

    but it isn't difficult to see whats going on

    myform.top=0
    myform.left=0
    myform.width=screen.width
    myform.height=screen.height
    'taking it for granted that
    'the border is double or sizable
    myimage.width=(myform.width-120)
    myimage.height=myform.height-420
    myimage.stretch=true

    load picture



    DocZaf
    {;->


  7. #7
    Lively Member
    Join Date
    May 1999
    Posts
    100
    Use my code and add this

    Private Sub Form_Load()
    Me.Width = Screen.Width
    Me.Hight = Scree.Hight
    Form_Resize
    End Sub

    Now will the picturebox be adjust to the screen, and to the user so It shall not me resizeable just set the Form properties BorderStyle to 1 or 3 (depends if you want to use the Maximum and Minimum bottons).


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