PDA

Click to See Complete Forum and Search --> : Programmatically Masking an Image


YoungBuck
Feb 20th, 2001, 09:41 PM
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....



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!

HarryW
Feb 20th, 2001, 09:46 PM
Ouch, all those Get & SetPixels! It's painful just seeing them... can't you get an array of RGB values or something?

YoungBuck
Feb 20th, 2001, 10:00 PM
Not quite sure what that would accomplish HarryW, can you elaborate a lil' bit?

HarryW
Feb 20th, 2001, 10:19 PM
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 :rolleyes:

YoungBuck
Feb 20th, 2001, 10:25 PM
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. ;)