PDA

Click to See Complete Forum and Search --> : Resizing bitmap


Sep 6th, 2000, 02:11 PM
Can someone tell me how to resize a bitmap image in VB?
Thanks

Sep 6th, 2000, 03:09 PM
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.

Sep 6th, 2000, 03:13 PM
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.

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

wengang
Oct 22nd, 2000, 11:43 PM
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

kedaman
Oct 23rd, 2000, 03:38 AM
Change the size of the picturebox before you save

agent
Oct 27th, 2000, 09:52 PM
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


Open Filename For Binary As f