Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420

    Bitmaps,Pointers and pixel operations.

    Hi there , ive been looking for ways to speed up my dynamic masking tool http://www.indigorose.com/forums/sho...&highlight=dmt and ive found out that creating a pointer to a bmp is over 10x faster than using the Pset() method of pixel manipulation .
    In myprogram there is 2 forms with a picturebox on each one. I simply want to copy the pixels of a certain colorfrom Form1 to Form 2.At the moment the code im using is :
    Code:
    Public Sub MergePics(ReadColor As Long, WriteColor As Long)
    Dim ScanX, ScanY, PixelColor As Long
    For ScanX = 0 To Form2.Picture1.ScaleWidth - 1
        For ScanY = 0 To Form2.Picture1.ScaleHeight - 1
            PixelColor = Form2.Picture1.Point(ScanX, ScanY)
               Form1.Picture1.PSet (ScanX, ScanY), WriteColor
               End If
            Next ScanY
        Next ScanX
    End Sub
    ive been trying to work though this tutorial http://www.xtremevbtalk.com/showthread.php?t=25347
    The tutorial makes it all look so easy but to be honest im having a hard time working out how to do this.
    The Demo prog is supposed to take a 100x100 bitmap and turn all the pixels red using 3 different methods showing the time taken for each one.

    Code:
    Option Explicit
    Private Declare Function GetPixel Lib "gdi32" _
         (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function SetPixel Lib "gdi32" _
         (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    Dim pa As BCHPicArray.clsPicArray
    
    Private Sub Command1_Click()
    Dim x&, y&, t&
    t = timeGetTime()
    For y = 0 To Picture1.ScaleHeight - 1
        For x = 0 To Picture1.ScaleWidth - 1
            pa.DrawPixel x, y, vbRed
        Next x
    Next y
    t = timeGetTime() - t
    Picture1.Refresh
    Me.Caption = "PicArray=" & t
    t = timeGetTime()
    For y = 0 To Picture1.ScaleHeight - 1
        For x = 0 To Picture1.ScaleWidth - 1
            SetPixel Picture1.hdc, x, y, vbRed
        Next x
    Next y
    t = timeGetTime() - t
    Picture1.Refresh
    Me.Caption = Me.Caption & " SetPixel=" & t
    t = timeGetTime()
    For y = 0 To Picture1.ScaleHeight - 1
        For x = 0 To Picture1.ScaleWidth - 1
            Picture1.PSet (x, y), vbRed
        Next x
    Next y
    t = timeGetTime() - t
    Picture1.Refresh
    Me.Caption = Me.Caption & " PSet=" & t
    End Sub
    
    Private Sub Form_Load()
    Set pa = New clsPicArray
    pa.LoadPicArray Picture1.Picture
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Set pa = Nothing
    End Sub
    But the image only turns red twice even though a time of 350ish is displayed for the first operation. So thinking the first time might be to fast to see i cut the code down to just use the PicArray method;

    Code:
    Option Explicit
    Private Declare Function GetPixel Lib "gdi32" _
         (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function SetPixel Lib "gdi32" _
         (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    Dim pa As BCHPicArray.clsPicArray
    Private Sub Form_Load()
    Set pa = New clsPicArray
    pa.LoadPicArray Picture1.Picture
    End Sub
    
    Private Sub Command1_Click()
    Dim x&, y&, t&
    For y = 0 To Picture1.ScaleHeight - 1
        For x = 0 To Picture1.ScaleWidth - 1
            pa.DrawPixel x, y, vbRed
        Next x
    Next y
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    Set pa = Nothing
    End Sub
    But The pixels dont change to red. This tutorial is replicated all over the net so i cant see the code being wrong at all,but the forum where it was origionaly posted has closed the thread so i can ask the guy who wrote it. Ive included a copy of the tutorial in the zipfile rather than post it up here. Any help on this would be much appreciated. thanks.
    Attached Files
    Last edited by clueless; 01-25-2008 at 08:58 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    I gave up one this code in the end and found a better example to work from. Ill post up the new 13x faster dynamic masking tool shortly

Similar Threads

  1. Get Pixel Color using x,y coordinates
    By CrazyFrog in forum AutoPlay Media Studio 6.0
    Replies: 10
    Last Post: 04-16-2007, 01:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts