|
-
Sep 6th, 2000, 02:11 PM
#1
Can someone tell me how to resize a bitmap image in VB?
Thanks
-
Sep 6th, 2000, 03:09 PM
#2
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
#3
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
-
Oct 22nd, 2000, 11:43 PM
#4
Frenzied Member
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
-
Oct 23rd, 2000, 03:38 AM
#5
transcendental analytic
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.
-
Oct 27th, 2000, 09:52 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|