Results 1 to 6 of 6

Thread: Zoom

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Arrow Zoom

    Hello there, I was asked to make a program to zoom a picture based on an algorithm given by my professor.

    The real problem here is that I have to get the array of Bytes of a picture, then manipulate them to get a new array of Bytes and then place this array in a picturebox...

    I know how to get the array of Bytes from a PictureBox but I do not know how to Put an array of Bytes into a picture box... Could somebody tell me how to do this?

    I also need to know on which pixel the user is clicking so I can know the area I am going to zoom in.

    Other ideas are welcomed...

    Thanks in Advance
    Last edited by Tec-Nico; Nov 4th, 2002 at 10:32 PM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well, on the MouseDown event there are X and Y values, so I suppose you could use those, or the GetCursorPos() API call. And look up SetBitmapBits or SetDIBits or something to that extent for selecting it into a DC.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    And how would you use SetBitmapBits?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I think vbaccelerator.com has a full class that you can change DIB sections with... I used it once, got like 20 fps on a 640x480 image It's pretty fast.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    So.. What do you recommend?

    I tried using the following code but it won't work. It will just show me a black rectangle... What am I doing wrong?


    VB Code:
    1. '--- Code in BmpModule ---
    2. Private Type BitMap
    3.     bmType As Long
    4.     bmWidth As Long
    5.     bmHeight As Long
    6.     bmWidthBytes As Long
    7.     bmPlanes As Integer
    8.     bmBitsPixel As Integer
    9.     bmBits As Long
    10. End Type
    11.  
    12. Public StartPosX As Single
    13. Public StartPosY As Single
    14. Public EndPosX As Single
    15. Public EndPosY As Single
    16.  
    17. Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    18. Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    19. Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    20. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    21.  
    22. Public Sub GetPart(Picture1 As PictureBox, Picture2 As PictureBox)
    23. Dim bmWidth As Long
    24. Dim bmHeight As Long
    25. Dim bmSize As Long
    26. Dim NewbmSize As Long
    27. Dim bmBits() As Byte
    28.  
    29. Dim bmZoomWidth As Long
    30. Dim bmZoomHeight As Long
    31.  
    32. 'Get picture's Width and Height
    33. bmWidth = Picture1.Width
    34. bmHeight = Picture1.Height
    35.  
    36. bmZoomWidth = EndPosX - StartPosX
    37. bmZoomHeight = EndPosY - StartPosY
    38.  
    39. 'ReDefine Bit array to hold all pixels from picture box
    40. ReDim Bits(0 To bmWidth - 1, 0 To bmHeight - 1) As Byte
    41. 'ReDim BitsZoom(0 To bmZoomWidth - 1, 0 To bmZoomHeight - 1) As Byte
    42. ReDim BitsZoom(StartPosX To EndPosX - 1, StartPosY To EndPosY - 1) As Byte
    43.  
    44. 'Store size of bitmap in total pixels
    45. bmSize = bmWidth * bmHeight
    46.  
    47. 'Grab picture's pixels and load to Bit array
    48. GetBitmapBits Picture1.Image, bmSize, Bits(0, 0)
    49.    
    50. 'Get Bits Selected
    51. Dim Y As Long
    52. Dim X As Long
    53.  
    54. For Y = StartPosY To EndPosY - 1
    55.  For X = StartPosX To EndPosX - 1
    56.   BitsZoom(X - StartPosX, Y - StartPosY) = Bits(X, Y)
    57.  Next X
    58. Next Y
    59.  
    60. 'Load Bit array to picture box
    61. Picture2.Width = bmZoomWidth
    62. Picture2.Height = bmZoomHeight
    63.  
    64. NewbmSize = bmZoomWidth * bmZoomHeight
    65.  
    66. SetBitmapBits Picture2.Image, NewbmSize, BitsZoom(0, 0)
    67.  
    68. 'Redraw
    69. Picture2.Refresh
    70. End Sub
    71.  
    72. '--- Form's Code ---
    73. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    74. StartPosX = X
    75. StartPosY = Y
    76.  
    77. 'The Shape thing is to provide a sensation of selection
    78. With Shape1
    79.  .Left = X
    80.  .Top = Y
    81.  .Width = 0
    82.  .Height = 0
    83.  .BorderStyle = 5
    84.  .Visible = True
    85.  .Tag = ""
    86. End With
    87. End Sub
    88.  
    89. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    90. With Shape1
    91.  If Shape1.Visible = True And .Tag = "" Then
    92.   .Width = Abs(StartPosX - X)
    93.   .Height = Abs(StartPosY - Y)
    94.  End If
    95. End With
    96. End Sub
    97.  
    98. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    99. EndPosX = X
    100. EndPosY = Y
    101. Shape1.Tag = "Selected"
    102. End Sub
    103.  
    104. Private Sub CmdCopyAll_Click()
    105. StartPosY = 0
    106. EndPosY = Picture1.Height
    107. StartPosX = 0
    108. EndPosX = Picture1.Width
    109.  
    110. GetPart Picture1, Picture2
    111. End Sub
    112.  
    113. Private Sub CmdGetPart_Click()
    114. If Shape1.Visible = False Then
    115.  StartPosY = 0
    116.  EndPosY = Picture1.Height
    117.  StartPosX = 0
    118.  EndPosX = Picture1.Width
    119. Else
    120.  Shape1.Visible = False
    121. End If
    122.  
    123. Me.MousePointer = vbHourglass
    124. GetPart Picture1, Picture2
    125. Me.MousePointer = vbDefault
    126. End Sub
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  6. #6
    Addicted Member
    Join Date
    Oct 2002
    Location
    Somewhere out in space
    Posts
    151
    Go take a look at your other post about this

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