Results 1 to 7 of 7

Thread: Help making this faster [VB]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Help making this faster [VB]

    is there anyway i can make this go faster. right now it is taking around 2.4 seconds and i'm trying to get it to at least 2 or so.

    VB Code:
    1. Private Function strCoordinates(ImageURL As String, Referer As String) As String
    2.     Dim img() As Byte
    3.     Dim Pet As StdPicture
    4.     Dim ct As Integer
    5.     Dim ctx As Long
    6.     Dim cty As Long
    7.     Dim x As Long
    8.     Dim y As Long
    9.     Dim Value As Single
    10.  
    11.     GetSource "GET", "captcha_show.phtml?" & ImageURL, "www.neopets.com", "http://www.neopets.com/haggle.phtml?" & Referer, strSession, ""
    12.  
    13.     img = StrConv(strSource, vbFromUnicode)
    14.     Set Pet = ToJpg(img)
    15.     Set picPet.Picture = Pet
    16.  
    17.     Value = 4900000
    18.     Do Until ct <> 0
    19.         For y = 0 To picPet.ScaleHeight - 1
    20.         For x = 0 To picPet.ScaleWidth - 1
    21.         If GetPixel(picPet.hdc, x, y) < Value Then
    22.             ct = ct + 1
    23.             ctx = ctx + x
    24.             cty = cty + y
    25.         End If
    26.         Next x
    27.         Next y
    28.         Value = Value + 500000
    29.         DoEvents
    30.     Loop
    31.  
    32.     strCoordinates = "&x=" & Int(ctx / ct) & "&y=" & Int(cty / ct)
    33.     Set Pet = Nothing
    34. End Function

    thanks for any help
    Last edited by cx323; Sep 17th, 2005 at 10:34 PM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help making this faster [VB]

    Can you post the parameters you use to call it, and the ToJpg() routine, so I can test it?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: Help making this faster [VB]

    Quote Originally Posted by penagate
    Can you post the parameters you use to call it, and the ToJpg() routine, so I can test it?
    here you go.
    VB Code:
    1. Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" (ByRef hGlobal As Any, ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
    2. Private Declare Function OleLoadPicture Lib "olepro32.dll" (ByVal lpStream As IUnknown, ByVal lSize As Long, ByVal fRunMode As Long, ByRef riid As GUID, ByRef lplpObj As Any) As Long
    3. Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef pclsid As GUID) As Long
    4.  
    5. Private Type GUID
    6.   Data1 As Long
    7.   Data2 As Integer
    8.   Data3 As Integer
    9.   Data4(7) As Byte
    10. End Type
    11.  
    12. Public Function ToJpg(ByRef jpg() As Byte) As IPicture
    13.     Dim istrm As IUnknown
    14.     Dim tGuid As GUID
    15.  
    16.     If Not CreateStreamOnHGlobal(jpg(LBound(jpg)), False, istrm) Then
    17.         CLSIDFromString StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), tGuid
    18.         OleLoadPicture istrm, UBound(jpg) - LBound(jpg) + 1, False, tGuid, ToJpg
    19.     End If
    20.  
    21.     Set istrm = Nothing
    22. End Function

    actually here's the whole code. you can make any suggestions to make it faster, but i think what i posted is the slowest portion besides internet speed.
    Attached Files Attached Files
    Last edited by cx323; Sep 18th, 2005 at 12:32 PM.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Help making this faster [VB]

    You need to work with Device Independent Bitmaps to make it work faster. You can use a DIB to capture the image from the picturebox and then start working with it and manipulating it as you can get the bitmap bytes to a Long array or Byte array. As you can guess, getting data from an array is way faster than calling GetPixel a few thousand times.

    Unfortunatenaly I'm having a really bad day today and can't get myself focused and bright enough to show you some sample code. Though you ought to be able to find something with the search for DIB, Device Context, Bitmaps and stuff like that.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: Help making this faster [VB]

    Quote Originally Posted by Merri
    You need to work with Device Independent Bitmaps to make it work faster. You can use a DIB to capture the image from the picturebox and then start working with it and manipulating it as you can get the bitmap bytes to a Long array or Byte array. As you can guess, getting data from an array is way faster than calling GetPixel a few thousand times.

    Unfortunatenaly I'm having a really bad day today and can't get myself focused and bright enough to show you some sample code. Though you ought to be able to find something with the search for DIB, Device Context, Bitmaps and stuff like that.
    i found some stuff by searching google, but i was wondering if you could post some sample code if you get the time. thanks

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Help making this faster [VB]

    http://www.vb-helper.com/howto_make_8bit_dib.html

    Here is an 8-bit DIB example. It should be possible to convert that to a 32-bit DIB code: just forget about palette and set BitCount to 32. The good thing in 32-bit is that you don't have to care about the "each line much be dividable by four bytes", as 32-bit is four bytes.

  7. #7
    New Member
    Join Date
    Dec 2005
    Posts
    11

    Re: Help making this faster [VB]

    studying...................
    just wanted things!!!
    hehe

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