Results 1 to 6 of 6

Thread: Resizing bitmap

  1. #1
    Guest

    Wink

    Can someone tell me how to resize a bitmap image in VB?
    Thanks

  2. #2
    Guest
    Load your picture in an ImageBox and set the Stretch property to True. Now when you resize it, the bitmap will stretch to fit the dimensions of the ImageBox.

  3. #3
    Guest
    Or if you need to use a PictureBox instead (for whatever reason) use the following method:

    Add 2 PictureBoxes to your Form and load your picture into Picture2. When you run the program, press + (Add) to enlarge the image and press - (subtract) to decrease the size.
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        'Make the Picture twice as large
        If KeyCode = vbKeyAdd Then
            With Picture1
                .Cls
                .Width = .Width * 2
                .Height = .Height * 2
                .PaintPicture Picture2.Picture, 0, 0, .ScaleWidth, .ScaleHeight
            End With
        End If
    
        'Make the Picture twice as small
        If KeyCode = vbKeySubtract Then
            With Picture1
                .Cls
                .Width = .Width / 2
                .Height = .Height / 2
                .PaintPicture Picture2.Picture, 0, 0, .ScaleWidth, .ScaleHeight
            End With
        End If
    
        'Center the PictureBox
        Picture1.Move (Me.ScaleWidth / 2) - (Picture1.Width / 2), (Me.ScaleHeight / 2) - (Picture1.Width / 2)
    End Sub
    
    Private Sub Form_Load()
        'Make Picture2 invisible
        Picture2.Visible = False
        'Make the Form recieve Key events before Controls
        Me.KeyPreview = True
        'ReDraw the Picture so it doesn't get cut off
        Picture1.AutoRedraw = True
        'Draw the Picture on to Picture1
        Picture1.PaintPicture Picture2.Picture, 0, 0
    End Sub

  4. #4
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Megatron, is there any way that I can load a jpg into the picture box then paint it to another picture box (or image box for either), where the new picture is smaller, then save the new, smaller picture as a bitmap with the new dimensions?

    Everything I have tried so far saves the new image with the same dimensions as the old .


    What do you think?

    Thanks
    Wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Change the size of the picturebox before you save
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    Assuming vb5 here but, vb5 will not save to jpg. It will only save to .bmp or .ico (if the pic is an icon) To save to a .jpg, you'll need an ActiveX control to do it (vbAccelerator has one for free) or you can be the first person to save a .jpg in vb using

    Code:
    Open Filename For Binary As f

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