Link to home
Start Free TrialLog in
Avatar of stchua
stchua

asked on

Resize Image and save the resized version into a new file

I'm  now doing a project that requires me to convert an image
into a smaller size and save it into another file. In the other words, to create thumb nails for picture. Pls help!!!!!!!!!!
Avatar of stchua
stchua

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of HATCHET
HATCHET

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
stchua,

Feel free to UP the points on this one for the extra work I did on it if you like.       =]

HATCHET
'Another way to save or view a thumbnail of a picture loaded into a picturebox:

Option Explicit
Const MAX_SIZE = 800 'Twips

Private Sub Command1_Click()
    Dim h As Long
    Dim w As Long
    Dim pic As StdPicture
    On Error GoTo THUMBERR
    'Get the picture loaded in picSrc
    'or load a picture using the "Open" dialog box
    Set pic = picSrc.Picture
    'Make sure we have a picture
    If pic = 0 Then Exit Sub
    'Convert the height and width to twips
    h = ScaleY(pic.Height, vbHimetric, vbTwips)
    w = ScaleX(pic.Width, vbHimetric, vbTwips)
    'Scale the destination picturebox to maintain
    'the same aspect ratio as original picture
    'but have max dimension of MAX_SIZE
    With picDst
    If w > h Then
        .Width = MAX_SIZE
        .Height = (h / w) * MAX_SIZE
    Else
        .Height = MAX_SIZE
        .Width = (w / h) * MAX_SIZE
    End If
    'Clear previous image and picture
    .Cls
    .Picture = LoadPicture("")
    'Scale the picture into the destination picbox
    .PaintPicture pic, 0, 0, .Width, .Height, 0, 0, w, h, vbSrcCopy
    'Convert the drawn image to the picture
    Set .Picture = .Image
    'Optionally save with "Save As" dialog box:
    '''SavePicture .Picture, "c:\thumb.bmp"
    End With
    'Clear the pic object
    Set pic = Nothing
    Exit Sub
THUMBERR:
    MsgBox Err.Description
    Err.Clear
End Sub

Private Sub Form_Load()
    '''picDst.Visible = False
    picDst.ScaleMode = 1 'Twip
    picDst.AutoRedraw = True
End Sub
Erick37,

Good suggestion there too!      =]

I tried it and it works well.