Results 1 to 5 of 5

Thread: stretch image

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Far Far Away
    Posts
    28

    stretch image

    hi guys
    i have a picture box
    when i do something i have made it so the picture box loads the picture
    only problem is it is too big for the box
    so does anyone know the code for making the picture box stretch so the whole image is visible ?

    cheers
    ..::Knoyali::..
    Life is a game

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Use the API StretchBlt call.

    This example is from allapi
    VB Code:
    1. 'This project needs:
    2. '- two picture boxes
    3. '- a button
    4. Private Type POINTAPI
    5.     X As Long
    6.     Y As Long
    7. End Type
    8.  
    9. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    10. Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
    11. Private Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Long
    12. 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
    13. Private Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
    14. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
    15. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    16.  
    17. Const ScrCopy = &HCC0020
    18. Const Yellow = &HFFFF&
    19. Private Sub Form_Load()
    20.     'KPD-Team 1998
    21.     'URL: [url]http://www.allapi.net/[/url]
    22.     'E-Mail: [email]KPDTeam@Allapi.net[/email]
    23.     Dim Cnt1 As Byte, Cnt2 As Byte, Point As POINTAPI
    24.     'Set the graphic mode to persistent
    25.     Me.AutoRedraw = True
    26.     'API uses pixels
    27.     Me.ScaleMode = vbPixels
    28.     Picture1.ScaleMode = vbPixels
    29.     Picture2.ScaleMode = vbPixels
    30.     'No borders
    31.     Picture1.BorderStyle = 0: Picture2.BorderStyle = 0
    32.     'Set the button's caption
    33.     Command1.Caption = "Paint && Stretch"
    34.     'Set the graphic mode to 'non persistent'
    35.     Picture1.AutoRedraw = False: Picture2.AutoRedraw = False
    36.     For Cnt1 = 0 To 100 Step 3
    37.         For Cnt2 = 0 To 100 Step 3
    38.             'Set the start-point's coördinates
    39.             Point.X = Cnt1: Point.Y = Cnt2
    40.             'Move the active point
    41.             MoveToEx Me.hdc, Cnt1, Cnt2, Point
    42.             'Draw a line from the active point to the given point
    43.             LineTo Me.hdc, 200, 200
    44.         Next Cnt2
    45.     Next Cnt1
    46.     For Cnt1 = 0 To 100 Step 5
    47.         For Cnt2 = 0 To 100 Step 5
    48.             'Draw a pixel
    49.             SetPixel Me.hdc, Cnt1, Cnt2, Yellow
    50.         Next Cnt2
    51.     Next Cnt1
    52. End Sub
    53. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    54.     Dim XX As Long, YY As Long, A As Long
    55.     XX = X: YY = Y
    56.     'Set the picturebox' backcolor
    57.     Picture2.BackColor = GetPixel(Picture1.hdc, XX, YY)
    58. End Sub
    59. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    60.     If Button = 1 Then
    61.         Dim XX As Long, YY As Long, A As Long
    62.         XX = X: YY = Y
    63.         'Set the picturebox' backcolor
    64.         Picture2.BackColor = GetPixel(Picture1.hdc, XX, YY)
    65.     End If
    66. End Sub
    67. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    68.     Dim XX As Long, YY As Long, A As Long
    69.     XX = X: YY = Y
    70.     'Set the picturebox' backcolor
    71.     Picture2.BackColor = GetPixel(Picture1.hdc, XX, YY)
    72. End Sub
    73. Private Sub Command1_Click()
    74.     'Set the width and height
    75.     Picture2.Width = 100: Picture2.Height = 100
    76.     Picture1.Width = 50: Picture1.Height = 50
    77.     'No pictures
    78.     Picture1.Picture = LoadPicture("")
    79.     DoEvents
    80.     Copy the desktop to our picturebox
    81.     PaintDesktop Picture1.hdc
    82.     'Stretch the picture
    83.     StretchBlt Picture2.hdc, 0, 0, 100, 100, Picture1.hdc, 0, 0, 50, 50, ScrCopy
    84. End Sub
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    For a PictureBox just set the AutoSize property to True.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Far Far Away
    Posts
    28
    i dont spose you could help me out by posting the code

    i mean i used F1 and found the stretch properties
    tried to follow instructions
    but it wasnt working
    maybe coz im stil new to vb lol

    and coz all you g uys are the pros maybe you can put in code correctly lol coz i just seem to muff it up

    cheers fellow dude
    ..::Knoyali::..
    Life is a game

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Far Far Away
    Posts
    28
    lol i reckon that autosize is a lot simpler thx dude
    ..::Knoyali::..
    Life is a game

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