|
-
Aug 27th, 2000, 10:04 PM
#1
Thread Starter
Hyperactive Member
I have a bitmap (I don't know the dimension) and I need to put it into my VB program (either PictureBox or Image is OK)
I try to use the Stretch, but it stretch my picture box, instead of expand or compress my bitmap image.
How can I expand or compress my bitmap?
-
Aug 27th, 2000, 10:12 PM
#2
Frenzied Member
well, to start, you can find the dimensions of your bmp by opening it in MS Paint and choosing IMAGE >> ATTRIBUTES.
When you get the pixels , multiply by 15 and that will be the twip size.
For example an image 200x300 pixels has twip size 3000x4500.
To put the image in your program you can either set an image or picture box to those dimensions and then insert the picture, or you can put an IMAGE box on the form and set STRETCH to FALSE. WHen you assign the image, that will make the image box exactly the size of your bitmap.
NOW, if you wanted to have the same picture on your form in the same proportions, but smaller or larger, let me know, because I just wrote a small piece of code like that for a screensaver.
Good luck.
-
Aug 27th, 2000, 10:18 PM
#3
Frenzied Member
well, what the heck.
this is what i came up with
==============================
strPicFile = (the path to your pic)
Image2.Picture = LoadPicture(strPicFile)
If Image2.Width > Image2.Height Then
Image1.Width = 3000
Image1.Height = (Image1.Width / Image2.Width) * Image2.Height
Image1.Picture = Image2.Picture
End If
If Image2.Width <= Image2.Height Then
Image1.Height = 3000
Image1.Width = (Image1.Height / Image2.Height) * Image2.Width
Image1.Picture = Image2.Picture
End If
=======================================
In this case, image2 has visible set to FALSE and stretch set to false
image1 has Visible set to TRUE and stretch set to true
When you run it, the pic will appear in correct dimensions on full screen. to change from full screen to set dimensions, just change my Screen.Width or Screen.Height to set numbers.
Okay, again, good luck.
-
Aug 27th, 2000, 10:23 PM
#4
Thread Starter
Hyperactive Member
Thanks Wengang,
First, I am not going to change the size of my picture box / image box
Second, I miss out the fact that the .bmp is created during runtime of my program, so I cannot go to MSPaint
Third, the size of the picture box is fixed but the .bmp is variant
Actually, I am going to print various bitmaps (I don't know the size) to printer, so I must limit the output dimension, and enlarge/compress (proportionally) the bitmap file.
-
Aug 28th, 2000, 03:26 AM
#5
transcendental analytic
You could use painpicture to stretch the pictures, in pictureboxes or forms, check out the vbhelp for usage, or search for paintpicture in this forum
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.
-
Aug 28th, 2000, 03:39 AM
#6
Thread Starter
Hyperactive Member
Thanks Kedaman,
I follow your idea by:
1. create a picture box sp to store the original picture
2. create a picture box np with my desired dimension
3. Use np.PaintPicture sp.Picture, 1, 1, np.Width, np.Height
I can get the picture in sp, to compress or expand into np
One further question, when I try to use
SavePicture np.Picture, "c:\temp\anything.bmp"
It comes out error message telling me that the value is wrong
If I run in IDE, np.Picture = 0
Could you help?
-
Aug 28th, 2000, 04:45 AM
#7
That is because you haven't loaded a picture in the PictureBox you have drawn the picture.
To get the drawn picture use the Image property instead of the Picture property.
Code:
SavePicture np.Image, "c:\temp\anything.bmp"
Good luck!
-
Aug 28th, 2000, 05:11 AM
#8
transcendental analytic
Or you could set the image to the picture
Code:
Set np.Picture = np.Image
Or you could set autoredraw to true
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.
-
Aug 28th, 2000, 05:57 AM
#9
Originally posted by kedaman
Or you could set autoredraw to true
?????????????
Setting AutoRedraw to True will not persist the image. It will only redraw the image when needed.
-
Aug 28th, 2000, 07:05 AM
#10
transcendental analytic
Youre right Joacim, that's if you have a picture from the beginning, which apparently isn't the case
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.
-
Aug 28th, 2000, 09:53 AM
#11
Put the following into a Form with a 2 PictureBoxes and a CommandButton. Make sure there is a picture loaded in Picture2.
Code:
Private Sub Command1_Click()
SavePicture Picture1.Image, "C:\Windows\Desktop\MyFile.bmp"
End Sub
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()
Picture2.Visible = False
Me.KeyPreview = True
Picture1.AutoRedraw = True
Picture1.PaintPicture Picture2.Picture, 0, 0
End Sub
When you press + (Add), the Bitmap will grow twice it's size and when you press - (Subtract), the bitmap will shrink to half it's amount.
-
Aug 30th, 2000, 01:01 AM
#12
Thread Starter
Hyperactive Member
kedaman, I tried the code and it works....
but, when I save the np.picture, it saves with the original dimension, not the one that I see on the screen (that has been compressed or enlarged).
How I can save the enlarged image?
Secondly, I tried to draw a button on the picture box (ie the picturebox as the parent), how I can save the 'look' of the picture box to a bmp, including the button?
Can anybody help?
-
Aug 30th, 2000, 03:27 AM
#13
transcendental analytic
Savepicture should save the image with the dimensions your picturebox or form have, so you should resize it before saving.
To capture the button too it won't work with savepicture because the button isn't included in the picture. You could use Bitblt api(searh for it to find the declaration) Then you set autoredraw to false, blit the picture to another picture which autoredraw should be set to true, and save that image.
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.
-
Aug 30th, 2000, 03:43 AM
#14
Thread Starter
Hyperactive Member
kedaman,
I already can see the compressed picture in the picture box, (I use a wrong ratio so that the picture will look very different)
and then I use a command button to save the picture.
But if I open the bmp file using MSPaint, the ratio is like as if it is not compressed.
-
Aug 30th, 2000, 04:13 AM
#15
transcendental analytic
That's because the picture doesn't match the image. did you do this?
Code:
SavePicture np.Image, "c:\temp\anything.bmp"
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.
-
Aug 30th, 2000, 04:28 AM
#16
Thread Starter
Hyperactive Member
I tried various way and the results are as follow:
(SrcPic already Set Picture property, while NewPic has Picture property = None)
Case 1:
NewPic.PaintPicture SrcPic.Picture, 1, 1, NewPic.ScaleWidth, NewPic.ScaleHeight
SavePicture NewPic.Picture, "c:\xxnew.bmp"
==> Error for second statement
Case 2:
NewPic.PaintPicture SrcPic.Picture, 1, 1, NewPic.ScaleWidth, NewPic.ScaleHeight
SavePicture NewPic.Image, "c:\xxnew.bmp"
==> I can see the compressed picture in NewPic, but the saved bmp only has a grey background and nothing on it
Case 3:
Set NewPic.Picture = SrcPic.Picture
NewPic.PaintPicture SrcPic.Picture, 1, 1, NewPic.ScaleWidth, NewPic.ScaleHeight
SavePicture NewPic.Picture, "c:\xxnew.bmp"
==> The saved bmp file is exactly the same as SrcPic.Picture (without any compression)
Could you help?
-
Aug 30th, 2000, 04:45 AM
#17
transcendental analytic
Code:
for 1:
put
newpicture.picture=newpicture.image
between the lines
for 2:
set autoredraw to true on newpicture
for 3:
save the image instead of the picture
but well you could choose one of them
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.
-
Aug 30th, 2000, 04:56 AM
#18
Thread Starter
Hyperactive Member
I use the second method, and it works now.
THANK YOU KEDAMAN
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
|