Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to stretch a picture?

Status
Not open for further replies.

ultra2

Programmer
Jun 26, 2005
46
HU
I have a pic in an image control.

I need to stretch it to a smaller size

plz help
 
You could use the .Stretch property of the image control. It will more than likely not size it perfectly. I believe there are API calls to do this but off the top of my head I can't think if them.

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
I think the API you are looking for is StretchBlt.

If you search this site (providing I'm right) you should turn up several examples of using it.

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Set Autosize for the picturebox control false then set it's size by setting width and height
 
not sure of the exact thread this code came from, but this is demo code provided by strongm.

Code:
Option Explicit

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long

Private Enum StretchMode
    BLACKONWHITE = 1
    WHITEONBLACK = 2
    COLORONCOLOR = 3
    HALFTONE = 4
End Enum

Private Sub Command1_Click()
    Dim Stretch As StretchMode
    
    
    For Stretch = BLACKONWHITE To HALFTONE
        SetStretchBltMode Form1.hdc, Stretch
        StretchBlt Form1.hdc, 0, (Stretch - 1) * 150, 100, 100, Picture1.hdc, 0, 0, 200, 200, vbSrcCopy
    Next
End Sub

Private Sub Form_Load()

    Form1.AutoRedraw = False ' ensure this, as autoredraw true resets stretchmode
    
    ' Rough and ready resizing just for the sake of this example
    Picture1.Left = 100 * Screen.TwipsPerPixelX
    Picture1.Width = 200 * Screen.TwipsPerPixelX
    Picture1.Height = 200 * Screen.TwipsPerPixelY
    
    Form1.Height = 650 * Screen.TwipsPerPixelY
    Form1.Width = 110 * Screen.TwipsPerPixelX + Picture1.Width
   
End Sub

u will need a command button and a picture box with a picture in it to resize.

good luck

If somethings hard to do, its not worth doing - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top