Results 1 to 4 of 4

Thread: resize image box or picture box?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2004
    Posts
    169

    resize image box or picture box?

    Is there any way to load a picture(.jpg file) to picture/image box and resize it proportionally? (the scale of length/width remains the same as orginal picture)


    thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: resize image box or picture box?

    You may use either Image control with Stretch = True or use sample below for Picturebox.
    Also KIM that image might not be as of original quality.
    VB Code:
    1. Public Sub ZoomPicture(pct As PictureBox, zoom As Double)
    2.     With pct
    3.         .Width = .Width * zoom
    4.         .Height = .Height * zoom
    5.         .PaintPicture .Picture, 0, 0, .ScaleWidth, .ScaleHeight
    6.     End With
    7. End Sub
    Ratio (zoom level) should be calculated based on original versus new size:

    OriginalWidth / NewWidth or something like that.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2004
    Posts
    169

    Re: resize image box or picture box?

    thanks,
    but I tried this sample, why is that the original image is obviously the different shape(one is square which means the width and height are same,the other one is very narrow), but after resize they all come up with same size/shape as my picture box, with a little distorted

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: resize image box or picture box?

    As I said image will be distorted ... Try this another quick sample and let me know if it works for you:
    VB Code:
    1. Private Sub Command1_Click()
    2. '============================
    3. Dim pctTemp As PictureBox
    4. Dim blnHigher As Boolean
    5. Dim dRatio As Double
    6.  
    7.     Set pctTemp = Controls.Add("VB.Picturebox", "picTemp")
    8.     pctTemp.AutoSize = True
    9.     pctTemp.Visible = False
    10.     pctTemp.Picture = LoadPicture("C:\My Documents\Images\JPG\someimage.jpg")
    11.    
    12.     blnHigher = IIf(pctTemp.Height > pctTemp.Width, True, False)
    13.     dRatio = pctTemp.Height / pctTemp.Width
    14.    
    15.     With Picture1
    16.         .AutoRedraw = True
    17.         If blnHigher Then
    18.             .Height = 3000
    19.             .Width = 3000 / dRatio
    20.         Else
    21.             .Width = 3000
    22.             .Height = 3000 * dRatio
    23.         End If
    24.         .PaintPicture pctTemp.Picture, 0, 0, .ScaleWidth, .ScaleHeight
    25.         Set .Picture = .Image
    26.     End With
    27.    
    28.     Controls.Remove "picTemp"
    29.     Set pctTemp = Nothing
    30.  
    31. 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