Results 1 to 9 of 9

Thread: efficiency! where are you!

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Question efficiency! where are you!

    I tried to make a "simple" test program that copies a picture from a picturebox to another picturebox, pixel by pixel. But that takes a while, even though I'm not doing any kind of process on the image.
    Can you guys please download the program that I made and take a look at it and see how can I make it faster? I'm sure it should be easy...
    (This is a test program, I know how to copy a picture from a picturebox to another, I just need help on the speed of the process )
    tnx for the help

  2. #2
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    SetPixelV is supposed to be faster, but I didn't see any difference in speed when I tried it. Can't you just BitBlt the whole image at once, and it will go a lot faster? Look what I did to the project and you see if you can do this.
    <removed by admin>

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    thanks for the help, but SetpixelV is slower. I dont want to use bitblt because I want to add effects to the picture (this is just a sample to test the speed first.)
    still looking for it

  4. #4
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    I don't think you are going to get any faster without using somthing other than setpixel. I don't know of any other way to do it though. What if you bitblt the image, and then use setpixel to change only pixels that you want to add the effects to? I don't know how to do that, but it sounds like it would work in theory. (And everything works in theory )
    <removed by admin>

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehehe, I hope it was that easy
    what if I want to edit all the pixels!!?!!!

  6. #6
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    If you want to edit all the pixels, then your SOL (***** Outta Luck) . You will just have to deal with the slow .8 seconds it takes to do that. What's wrong with .8 seconds anyway?
    <removed by admin>

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Looping through all the pixels in a picture box will be slow.
    However I made a few changes to the code that makes it slighter faster.
    I simply added more variables so you don't read property values more then once.
    Checking the property value of an object is slower then using a variable.
    You're also loop to picSrc.ScaleWidth and picSrc.ScaleHeight but it should be one less since the first pixel is at position 0,0 and not 1,1.
    VB Code:
    1. Private Sub cmdStart_Click()
    2.     Dim x As Long, y As Long
    3.     Dim startTime As Long
    4.     Dim lngColor As Long
    5.     Dim nSW As Long, nSH As Long
    6.     Dim hSrcDC As Long, hDestDC As Long
    7.    
    8.     Dim blnRefresh As Boolean
    9.     picDest.Cls
    10.     hSrcDC = picSrc.hdc
    11.     hDestDC = picDest.hdc
    12.     blnRefresh = (chkRefresh.Value = vbChecked)
    13.     nSW = picSrc.ScaleWidth - 1 'don't loop longer then necassary
    14.     nSH = picSrc.ScaleHeight - 1
    15.     lblStatus.Caption = "Processing..."
    16.     lblStatus.Refresh
    17.     startTime = GetTickCount()
    18.     For x = 0 To nSW
    19.         For y = 0 To nSH
    20.             lngColor = GetPixel(hSrcDC, x, y)
    21.             SetPixel hDestDC, x, y, lngColor
    22.         Next y
    23.                
    24.         If blnRefresh = True And x Mod 5 = 0 Then
    25.             picDest.Refresh
    26.         End If
    27.     Next x
    28.  
    29.     lblStatus.Caption = "Done in " & (GetTickCount() - startTime) / 1000 & " seconds"
    30.     picDest.Refresh
    31. End Sub
    Best regards

  8. #8

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehehe, I never realized that those factors make the code slower... thanks alot
    But there should be a faster way though

  9. #9

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I'm still looking for a solution, please help!

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