Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleResize a picture using PaintPicture and save it into a bitmap file
DescriptionThis example shows how to resize a picture using PaintPicture and save it into a bitmap file in Visual Basic 6. The only real trick is to set the result PictureBox's Picture property equal to its Image property to make the image permanent.
Keywordsresize, PaintPicture, bitmap
CategoriesControls, Graphics
 
Use PaintPicture to copy the picture from the source PictureBox to the destination PictureBox, resizing it appropriately. Set the result PictureBox's Picture property equal to its Image property to make the image permanent. Then use SavePicture to save the results into a bitmap file.
 
Private Sub Command1_Click()
Dim file_name As String

    ' Resize the picture.
    Picture2.AutoRedraw = True
    Picture2.PaintPicture Picture1.Picture, _
        Picture2.ScaleLeft, Picture2.ScaleTop, _
            Picture2.ScaleWidth, Picture2.ScaleHeight, _
        Picture1.ScaleLeft, Picture1.ScaleTop, _
            Picture1.ScaleWidth, Picture1.ScaleHeight
    Picture2.Picture = Picture2.Image

    ' Save the result.
    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = _
        file_name & "\"
    SavePicture Picture2.Picture, file_name & "small.bmp"
End Sub

Private Sub Form_Load()
Dim edge As Single

    edge = Picture1.Width - Picture1.ScaleWidth
    Picture2.Width = (Picture1.Width - edge) / 2 + edge
    Picture2.Height = (Picture1.Height - edge) / 2 + edge
    Me.Width = Picture2.Left + Picture2.Width + 240
End Sub
 
For more information on graphics programming in Visual Basic, see my book Ready-to-Run Visual Basic Graphics Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated