Results 1 to 6 of 6

Thread: [RESOLVED] Resize image proportionally?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    33

    Resolved [RESOLVED] Resize image proportionally?

    hi

    I have the following simple form which allows the user to select and view an image. However currently all images are set to stretch to fit the space given. I want to be able to resize the image in proportion to fit inside the space.

    Any help would be great.

    Here's the code:

    Code:
    Private Sub Dir1_Change()
        File1.Path = Dir1.Path        'Update files.
    End Sub
    
    Private Sub Drive1_Change()
        Dir1.Path = Drive1.Drive      'Update directory path.
    End Sub
    
    Private Sub File1_Click()
        If Right(File1.Path, 1) <> "\" Then
            Label1.Caption = File1.Path & "\" & File1.FileName
        Else                          'If root directory
            Label1.Caption = File1.Path & File1.FileName
        End If
        frmPhoto.Open.Picture = LoadPicture(Label1.Caption)
    End Sub
    
    Private Sub cmdSave_Click()
        If Right(File1.Path, 1) <> "\" Then
            pic = File1.Path & "\" & File1.FileName
        Else                          'If root directory
            pic = File1.Path & File1.FileName
        End If
        frmEmployee.txtPhoto.Text = pic
        
        '-----Add notice to lblNotice on frmMain
            
        frmMain.lblNotice.Caption = ""
        frmMain.lblNotice.Caption = "Photo Added"
        
        Unload Me
    End Sub
    edit: vbcode tags not working for some reason

    ... and the form:
    Attached Images Attached Images  
    Last edited by Pino; Jul 22nd, 2005 at 06:55 AM.

  2. #2
    Addicted Member
    Join Date
    May 2004
    Location
    Nagpur, India
    Posts
    228

    Re: Resize image proportionally?

    add an invisible Picture box to your form and fill the image in this form.
    Then, using BitBlt, transform the image from the invisble picture box to your Open picture box

  3. #3
    Addicted Member
    Join Date
    May 2004
    Location
    Nagpur, India
    Posts
    228

    Re: Resize image proportionally?

    Sorry, forgot to mention, BitBlt is an Win32 API function.
    Public Declare Function BitBlt Lib "gdi32.dll" ( _
    ByVal hDestDC As Long, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal hSrcDC As Long, _
    ByVal xSrc As Long, _
    ByVal ySrc As Long, _
    ByVal dwRop As Long) As Long

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    33

    Re: Resize image proportionally?

    So how exactly do I put that into the above code? (I'm a bit of a noob at VB)

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    33

    Re: Resize image proportionally?

    Is that the simplest way (the bitblt thing) while still being reasonably fast? ... still not sure how to use it though, any help?

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    33

    Re: Resize image proportionally?

    Just used a simple thing:

    VB Code:
    1. Private Sub File1_Click()
    2.     If Right(File1.Path, 1) <> "\" Then
    3.         txtPath.Text = File1.Path & "\" & File1.FileName
    4.     Else                          'If root directory
    5.         txtPath.Text = File1.Path & File1.FileName
    6.     End If
    7.  
    8. On Error GoTo handleit
    9.     frmPhoto.Open.Stretch = False
    10.     frmPhoto.Open.Picture = LoadPicture(txtPath.Text)
    11.     If frmPhoto.Open.Height >= 4875 Or frmPhoto.Open.Width >= 7600 Then
    12.         Do While frmPhoto.Open.Height >= 4875 Or frmPhoto.Open.Width >= 7600
    13.             frmPhoto.Open.Height = frmPhoto.Open.Height * 0.95
    14.             frmPhoto.Open.Width = frmPhoto.Open.Width * 0.95
    15.         Loop
    16.     frmPhoto.Open.Stretch = True
    17.     End If
    18.     frmPhoto.Open.Left = (Frame1.Width - frmPhoto.Open.Width) \ 2
    19.     frmPhoto.Open.Top = (Frame1.Height - frmPhoto.Open.Height) \ 2
    20. handleit:
    21.     Exit Sub
    22. End Sub

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