Results 1 to 12 of 12

Thread: image/picturebox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23

    image/picturebox

    is it possible to rotate an image that is inside a picturebox???? please help

  2. #2
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    Her you go:-
    Attached Files Attached Files

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    thnx but er.. my visual basic couldn't upgrade the file to visual basic.net2003 is there by anychance u could just type cut/paste the code realy quick?

  4. #4
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type POINTAPI
    4.     x As Long
    5.     y As Long
    6. End Type
    7.  
    8. Dim Pt(0 To 2) As POINTAPI
    9. Dim Angle As Double
    10.  
    11. Private Const PI As Double = 3.14159265358979
    12. Private Declare Function PlgBlt Lib "gdi32" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
    13.  
    14. Private Sub Slider1_Click()
    15.     Angle = Slider1 / 100
    16.     Rotate Picture2, Picture1, Angle
    17. End Sub
    18.  
    19. Private Sub Slider1_Scroll()
    20.     Angle = Slider1 / 100
    21.     Rotate Picture2, Picture1, Angle
    22. End Sub
    23.  
    24. Private Sub Rotate(picDest As PictureBox, picsrc As PictureBox, Angle As Double)
    25.  
    26.     Dim a As Integer
    27.    
    28.     Pt(0).x = 0
    29.     Pt(0).y = 0
    30.     Pt(1).x = picsrc.Width
    31.     Pt(1).y = 0
    32.     Pt(2).x = 0
    33.     Pt(2).y = picsrc.Height
    34.    
    35.     For a = 0 To 2
    36.         Pt(a) = RotateP(picsrc.Width / 2, picsrc.Height / 2, Pt(a), Angle)
    37.     Next
    38.     PlgBlt picDest.hDC, Pt(0), picsrc.hDC, 0, 0, picsrc.Width, picsrc.Height, ByVal 0&, ByVal 0&, ByVal 0&
    39.     picDest.Refresh
    40.    
    41. End Sub
    42.  
    43. Private Function RotateP(ByRef x As Long, ByRef y As Long, ByRef Point As POINTAPI, Angle As Double) As POINTAPI
    44.  
    45.     Dim Tmp1 As Double
    46.     Dim Tmp2 As Double
    47.  
    48.     Tmp1 = Point.x - x
    49.     Tmp2 = Point.y - y
    50.     Point.x = Tmp1 * Cos(Angle) - Tmp2 * Sin(Angle)
    51.     Point.y = Tmp1 * Sin(Angle) + Tmp2 * Cos(Angle)
    52.     Point.x = Point.x + x
    53.     Point.y = Point.y + y
    54.  
    55.     RotateP = Point
    56.  
    57. End Function

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    err....i'm in high shool doing my second semeseter of visual basic.....i don't understand half the code. is there a simple property value u can change to rotate the image?

  6. #6
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    Needs quie a lot of code depending what you wan to do.

    Try this thread for help many examples for tou to look through

    http://www.vbforums.com/search.php?s...ost&sortorder=

    Cheers

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    23
    question 2 how do u flip images like how do u get picMove1 to flip

  8. #8
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type POINTAPI
    4.     x As Long
    5.     y As Long
    6. End Type
    7.  
    8. Dim Pt(0 To 2) As POINTAPI
    9. Dim Angle As Double
    10.  
    11. Private Const PI As Double = 3.14159265358979
    12. Private Declare Function PlgBlt Lib "gdi32" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
    13.  
    14. Private Sub Slider1_Click()
    15.     Angle = Slider1 / 100
    16.     Rotate Picture1, Picture2, Angle 'Change this line
    17. End Sub
    18.  
    19. Private Sub Slider1_Scroll()
    20.     Angle = Slider1 / 100
    21.     Rotate Picture1, Picture2, Angle 'Change this line
    22. End Sub
    23.  
    24. Private Sub Rotate(picDest As PictureBox, picsrc As PictureBox, Angle As Double)
    25.  
    26.     Dim a As Integer
    27.    
    28.     Pt(0).x = 0
    29.     Pt(0).y = 0
    30.     Pt(1).x = picsrc.Width
    31.     Pt(1).y = 0
    32.     Pt(2).x = 0
    33.     Pt(2).y = picsrc.Height
    34.    
    35.     For a = 0 To 2
    36.         Pt(a) = RotateP(picsrc.Width / 2, picsrc.Height / 2, Pt(a), Angle)
    37.     Next
    38.     PlgBlt picDest.hDC, Pt(0), picsrc.hDC, 0, 0, picsrc.Width, picsrc.Height, ByVal 0&, ByVal 0&, ByVal 0&
    39.     picDest.Refresh
    40.    
    41. End Sub
    42.  
    43. Private Function RotateP(ByRef x As Long, ByRef y As Long, ByRef Point As POINTAPI, Angle As Double) As POINTAPI
    44.  
    45.     Dim Tmp1 As Double
    46.     Dim Tmp2 As Double
    47.  
    48.     Tmp1 = Point.x - x
    49.     Tmp2 = Point.y - y
    50.     Point.x = Tmp1 * Cos(Angle) - Tmp2 * Sin(Angle)
    51.     Point.y = Tmp1 * Sin(Angle) + Tmp2 * Cos(Angle)
    52.     Point.x = Point.x + x
    53.     Point.y = Point.y + y
    54.  
    55.     RotateP = Point
    56.  
    57. End Function

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Assuming from your "visual basic.net 2003" thing I think you should be posting in the VB.net section, not here. seriously it's right below this one. You can't miss it. You shouldn't have missed it.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,950

    Re: image/picturebox

    Quote Originally Posted by laserman
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type POINTAPI
    4.     x As Long
    5.     y As Long
    6. End Type
    7.  
    8. Dim Pt(0 To 2) As POINTAPI
    9. Dim Angle As Double
    10.  
    11. Private Const PI As Double = 3.14159265358979
    12. Private Declare Function PlgBlt Lib "gdi32" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
    13.  
    14. Private Sub Slider1_Click()
    15.     Angle = Slider1 / 100
    16.     Rotate Picture1, Picture2, Angle 'Change this line
    17. End Sub
    18.  
    19. Private Sub Slider1_Scroll()
    20.     Angle = Slider1 / 100
    21.     Rotate Picture1, Picture2, Angle 'Change this line
    22. End Sub
    23.  
    24. Private Sub Rotate(picDest As PictureBox, picsrc As PictureBox, Angle As Double)
    25.  
    26.     Dim a As Integer
    27.    
    28.     Pt(0).x = 0
    29.     Pt(0).y = 0
    30.     Pt(1).x = picsrc.Width
    31.     Pt(1).y = 0
    32.     Pt(2).x = 0
    33.     Pt(2).y = picsrc.Height
    34.    
    35.     For a = 0 To 2
    36.         Pt(a) = RotateP(picsrc.Width / 2, picsrc.Height / 2, Pt(a), Angle)
    37.     Next
    38.     PlgBlt picDest.hDC, Pt(0), picsrc.hDC, 0, 0, picsrc.Width, picsrc.Height, ByVal 0&, ByVal 0&, ByVal 0&
    39.     picDest.Refresh
    40.    
    41. End Sub
    42.  
    43. Private Function RotateP(ByRef x As Long, ByRef y As Long, ByRef Point As POINTAPI, Angle As Double) As POINTAPI
    44.  
    45.     Dim Tmp1 As Double
    46.     Dim Tmp2 As Double
    47.  
    48.     Tmp1 = Point.x - x
    49.     Tmp2 = Point.y - y
    50.     Point.x = Tmp1 * Cos(Angle) - Tmp2 * Sin(Angle)
    51.     Point.y = Tmp1 * Sin(Angle) + Tmp2 * Cos(Angle)
    52.     Point.x = Point.x + x
    53.     Point.y = Point.y + y
    54.  
    55.     RotateP = Point
    56.  
    57. End Function
    i have this project, and works... but when i try put in my project, like copy your functions and the variables, the code is ignored... but why the code is ignored?
    thank you

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: image/picturebox

    Quote Originally Posted by doggychow14
    question 2 how do u flip images like how do u get picMove1 to flip
    Heres a simple way to flip an image inside a picture box.
    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 Const SRCCOPY = &HCC0020
    Code:
    ' set pic box to pixel mode
    Picture1.ScaleMode = 3
    
    'To flip horizontally ...
    Call StretchBlt(Picture1.hdc, Picture1.ScaleWidth, 0, Picture1.ScaleWidth * -1, Picture1.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, SRCCOPY)
    
    'To flip vertically...
    Call StretchBlt(Picture1.hdc, 0, Picture1.ScaleHeight, Picture1.ScaleWidth, Picture1.ScaleHeight * -1, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, SRCCOPY)

  12. #12
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,950

    Re: image/picturebox

    Quote Originally Posted by Edgemeal
    Heres a simple way to flip an image inside a picture box.
    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 Const SRCCOPY = &HCC0020
    Code:
    ' set pic box to pixel mode
    Picture1.ScaleMode = 3
    
    'To flip horizontally ...
    Call StretchBlt(Picture1.hdc, Picture1.ScaleWidth, 0, Picture1.ScaleWidth * -1, Picture1.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, SRCCOPY)
    
    'To flip vertically...
    Call StretchBlt(Picture1.hdc, 0, Picture1.ScaleHeight, Picture1.ScaleWidth, Picture1.ScaleHeight * -1, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, SRCCOPY)
    thank you... thank you... but what i need is more complex... in Games and Graphics section one person is help me the rotation math...
    thank you my friend...

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