Results 1 to 5 of 5

Thread: Programmatically Masking an Image

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    OK here is a function I've written to create a mask of any image that is currently stored in a Device Context and it works wonderfully besides being slow as hell....

    Code:
    Public Sub MaskTo(ByVal phDC As Long, pTranspColor As Long)
     Dim lX As Long, lY As Long
    
     For lX = 0 To lngWdth
        For lY = 0 To lngHgt
            
            If GetPixel(lngDC, lX, lY) = pTranspColor Then
                
                SetPixelV phDC, lX, lY, vbBlack
                
            Else
                
                SetPixelV phDC, lX, lY, vbWhite
                
            End If
            
        Next lY
     Next lX
     
    End Sub
    What I'm wondering is if there is a better way of doing this as this method is slow and tedious, it seems I've seen this done a more efficient ways but I cannot seem to find the examples anywhere, so if anybody can get me on the right track it would be much appreciated. Thanks in advance!
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Ouch, all those Get & SetPixels! It's painful just seeing them... can't you get an array of RGB values or something?
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Not quite sure what that would accomplish HarryW, can you elaborate a lil' bit?
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well I mean it would be much much quicker if you could deal with the image as an array of RGB values, instead of GetPixel and SetPixel all the time. I only use DirecDraw for graphics stuff, and I also only really use C++, so I'm used to having everything in memory and... well.... quicker
    Harry.

    "From one thing, know ten thousand things."

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Well essentially this MaskTo function should only be called once and draws a mask to a seperate DC offscreen and then all the Blting stuff is done to make the image transparent, so in other words it would seem like a waste of memory to store the entire image as an array of pixels when this array should only be accessed once per image. I'm probably just being too picky but 8 - 10 seconds to make a mask of each image just seems like to much too me.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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