|
-
Jul 6th, 2005, 05:08 AM
#1
Thread Starter
Lively Member
how to stretch a picture?
how to stretch a picture?
I have a pic in an image control.
I need to stretch it to a smaller size
plz help
-
Jul 6th, 2005, 05:09 AM
#2
Re: how to stretch a picture?
Have you set the image control's Stretch property to True?
-
Jul 6th, 2005, 05:40 AM
#3
Re: how to stretch a picture?
 Originally Posted by ultra2
I need to stretch it to a smaller size
This sounds contridictory. Do you need to 'stretch' it or 'shrink' it?
-
Jul 6th, 2005, 06:01 AM
#4
Re: how to stretch a picture?
 Originally Posted by Hack
This sounds contridictory. Do you need to 'stretch' it or 'shrink' it?
Obviously he wanted to shrink it but it doesn't matter because the same code would be used.
If you only want to display the image in a smaller size you could as dee-u suggested just set the Stretch property of the Image control. However that would fit the picture inside the image control and not keep the aspect ratio between the width and the height of the image. To do that you need some simple calculations. However if you want to stretch or shrink an image and save it as a new image you would need to either use the StretchBlt API function or the VB built in PaintPicture method.
I will assume you only want to display like a thumbnail of the image on the screen, so first set the Stretch property of the image control to True and then use code simular to this to stretch or shrink the image control while still keeping the correct aspect ratio between the width and the height:
VB Code:
Public Sub StretchImage(img As Image, dblRatio As Double)
Dim pic As StdPicture
Dim w As Long, h As Long
Dim nScale As Long
Set pic = img.Picture
nScale = img.Parent.ScaleMode
img.Width = ScaleX(pic.Width, vbHimetric, nScale) * dblRatio
img.Height = ScaleY(pic.Height, vbHimetric, nScale) * dblRatio
End Sub
You can then call this Sub in the following manner:
VB Code:
Private Sub Command1_Click()
Call StretchImage(Image1, 0.5)
End Sub
That will shrink Image1 to half the width and height of the origional picture. You can pass a number higher then 1 to stretch the image. Just keep in mind that the ratio will always be from the origional picture size and not compared to the current width and height of the image control. So passing 1 as the aspect ratio will always resize the image control to the size the picture actually have.
One more warning. Make sure there is actually a picture loaded into the image control before calling this Sub or it will fail.
-
Jul 6th, 2005, 06:44 AM
#5
Hyperactive Member
Re: how to stretch a picture?
Last edited by Tamgovb; Jul 6th, 2005 at 06:51 AM.
I know, I know, my English is bad, sorry .....
-
Jul 6th, 2005, 07:55 AM
#6
Thread Starter
Lively Member
Re: how to stretch a picture?
I need to save it as a new picture!
-
Jul 6th, 2005, 08:00 AM
#7
Re: how to stretch a picture?
This code snippet at Planet Source Code might help.
After using StretchBlt, just try to save Picture.Image
-
Jul 6th, 2005, 11:23 AM
#8
Thread Starter
Lively Member
Re: how to stretch a picture?
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
|