how to stretch a picture?
I have a pic in an image control.
I need to stretch it to a smaller size
plz help
Printable View
how to stretch a picture?
I have a pic in an image control.
I need to stretch it to a smaller size
plz help
Have you set the image control's Stretch property to True?
This sounds contridictory. Do you need to 'stretch' it or 'shrink' it?Quote:
Originally Posted by ultra2
Obviously he wanted to shrink it but it doesn't matter because the same code would be used.Quote:
Originally Posted by Hack
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:You can then call this Sub in the following manner: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 SubThat 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.VB Code:
Private Sub Command1_Click() Call StretchImage(Image1, 0.5) End Sub
One more warning. Make sure there is actually a picture loaded into the image control before calling this Sub or it will fail.
Hi
Look, interesting example.
www.vb-helper.com/howto_stretch_picturebox.html
I need to save it as a new picture!
This code snippet at Planet Source Code might help.
After using StretchBlt, just try to save Picture.Image
thx a lot, it works