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:
Private Function strCoordinates(ImageURL As String, Referer As String) As String
Dim img() As Byte
Dim Pet As StdPicture
Dim ct As Integer
Dim ctx As Long
Dim cty As Long
Dim x As Long
Dim y As Long
Dim Value As Single
GetSource "GET", "captcha_show.phtml?" & ImageURL, "www.neopets.com", "http://www.neopets.com/haggle.phtml?" & Referer, strSession, ""
img = StrConv(strSource, vbFromUnicode)
Set Pet = ToJpg(img)
Set picPet.Picture = Pet
Value = 4900000
Do Until ct <> 0
For y = 0 To picPet.ScaleHeight - 1
For x = 0 To picPet.ScaleWidth - 1
If GetPixel(picPet.hdc, x, y) < Value Then
ct = ct + 1
ctx = ctx + x
cty = cty + y
End If
Next x
Next y
Value = Value + 500000
DoEvents
Loop
strCoordinates = "&x=" & Int(ctx / ct) & "&y=" & Int(cty / ct)
Set Pet = Nothing
End Function
thanks for any help
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?
1 Attachment(s)
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:
Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" (ByRef hGlobal As Any, ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
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
Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef pclsid As GUID) As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Public Function ToJpg(ByRef jpg() As Byte) As IPicture
Dim istrm As IUnknown
Dim tGuid As GUID
If Not CreateStreamOnHGlobal(jpg(LBound(jpg)), False, istrm) Then
CLSIDFromString StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), tGuid
OleLoadPicture istrm, UBound(jpg) - LBound(jpg) + 1, False, tGuid, ToJpg
End If
Set istrm = Nothing
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.
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.
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
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.
Re: Help making this faster [VB]
studying...................
just wanted things!!!
hehe