CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Scaling

  1. #1
    Join Date
    May 2001
    Location
    Kansas City, Missouri
    Posts
    45

    Scaling

    Does anybody know if there is a way to scale an image on a PictureBox control? Let me clarify this question a little bit. When the Control changes size, the image on the control also has to change size.

    Thanks in advance.


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Scaling

    Try this

    Picture1 is a picture box the size of your exisitng icon
    picture 2 is a picture the size you want it to be

    picture2.AutoRedraw is TRUE

    you can easily use this to re-size icons, bitmaps, jpeg's etc - could put this in your code, but I would
    use it to resize your icon once, then use the result

    the result is always a bitmap though.

    Option Explicit

    Private Sub Command1_Click()

    Dim retval As Long

    retval = StretchBlt(Picture2.hdc, 0, 0, Picture2.Width \ 15, Picture2.Height \ 15, _
    Picture1.hdc, 0, 0, Picture1.Width \ 15, Picture1.Height \ 15, SRCCOPY)

    SavePicture Picture2.Image, "c:\newpic.bmp"

    Picture2.Refresh

    End Sub

    'in a .bas

    Option Explicit

    Public Const SRCCOPY = &HCC0020


    Declare Function StretchBlt Lib "gdi32.dll" (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 hSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long


    Declare Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As
    Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal
    nYSrc As Long, ByVal dwRop As Long) As Long



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured