Acmlm's Board - I2 Archive - Programming - How do I invert colours?
User | Post |
HyperLamer
Posts: 1947/8210 |
Hey, that works too. ![](images/smilies/cute.gif) |
Dish
Posts: 161/596 |
*Disch kicks self
upon further research... I see there's a NOTSRCCOPY option which does a normal inverted blit. So you could replace the 2 bitblt calls with a single one using NOTSRCCOPY.
I must have just missed that one before or something... egads. ![](images/smilies/yuck.gif) |
HyperLamer
Posts: 1943/8210 |
Cool, blackness and mergepaint worked great. ![](images/smilies/cute.gif)
[edit] Any idea what's wrong with this?
Private Sub optTools_Click(Index As Integer) DrawMode = Index End Sub
If Index is 0, I get an Invalid Property Value error. DrawMode is a public integer in a module, and optTools is a control array of option buttons. Sure, NOW you tell me that DrawMode is a reserved keyword. *kicks VB* |
sloat
Posts: 8/85 |
You could also use PatBlt to draw an inverted rect over a device context if it applies better. It's sorta the same as BitBlt, but doesn't take any source bitmaps.
For more info: MSDN PatBlt
|
Dish
Posts: 159/596 |
Originally posted by Gavin
BitBlt picMain.hDC, 0, 0, picMain.Width, picMain.Height, picMain.hDC, 0, 0, vbDstInvert picMain.Refresh
invert picMain's colors.
are you sure Disch? i thought you would just use MERGEPAINT, then SRCAND to get a trainsparent image.. maybe i'm not understanding exactly what he was looking for... ![](images/smilies/cry.gif)
Well he said he wanted to just to an inverted blit, without changing the source image. The blit you gave looks like it would invert the source image (assuming picMain.hDC has the source image)
I guess DSTINVERT would work too... but only after the image is copied with SRCCOPY. Almost any way you slice it.... it's going to take 2 blits... which 2 you use could be different though:
SRCCOPY, then DSTINVERT WHITENESS, then SRCINVERT BLACKNESS, then MERGEPAINT or you could also load a solid white brush into the destination DC and blit with PATINVERT.
The PATINVERT route would probably be the fastest since it only involves one blit. After that I would assume the WHITENESS/BLACKNESS routes would be a little faster than the remaining route... but that's just a guess.
The MERGEPAINT and SRCAND combo doesn't look like it would work to me... it would make some interesting results, but it wouldn't be color inversion.
For an explaination of how the color is found for each of these blit methods (think I have all these right, you may want to doublecheck though):
SRCCOPY: dest = src DSTINVERT: dest = dest ^ 0xFFFFFFFF WHITENESS: dest = 0xFFFFFFFF SRCINVERT: dest = dest ^ src BLACKNESS: dest = 0 MERGEPAINT: dest = dest | (src ^ 0xFFFFFFFF) SRCAND: dest = dest & src
To do an inverted blit, you ultimately want: dest = src ^ 0xFFFFFFFF
I'm pretty sure the combos I mentioned will get you that result. MERGEPAINT and SRCAND will give you something funky though... like:
dest = (dest | (src ^ 0xFFFFFFFF)) & src |
Gavin
Posts: 294/799 |
Originally posted by Disch Yeah drawing on top won't matter... as long as the opaque image is drawn first.
typical opaque blit: BitBlt( destDC, destX, destY, wd, ht, srcDC, srcX, srcY, SRCCOPY );
inverted opaque blit: BitBlt( destDC, destX, destY, wd, ht, srcDC, srcX, srcY, WHITENESS ); BitBlt( destDC, destX, destY, wd, ht, srcDC, srcX, srcY, SRCINVERT );
I haven't tested this but it seems like it would work. I'm unsure how it would look in VB, but I'm sure the params are the same (or similar).
BitBlt picMain.hDC, 0, 0, picMain.Width, picMain.Height, picMain.hDC, 0, 0, vbDstInvert picMain.Refresh
invert picMain's colors.
are you sure Disch? i thought you would just use MERGEPAINT, then SRCAND to get a trainsparent image.. maybe i'm not understanding exactly what he was looking for... ![](images/smilies/cry.gif) |
Dish
Posts: 158/596 |
Yeah drawing on top won't matter... as long as the opaque image is drawn first.
typical opaque blit: BitBlt( destDC, destX, destY, wd, ht, srcDC, srcX, srcY, SRCCOPY );
inverted opaque blit: BitBlt( destDC, destX, destY, wd, ht, srcDC, srcX, srcY, WHITENESS ); BitBlt( destDC, destX, destY, wd, ht, srcDC, srcX, srcY, SRCINVERT );
I haven't tested this but it seems like it would work. I'm unsure how it would look in VB, but I'm sure the params are the same (or similar). |
HyperLamer
Posts: 1942/8210 |
I'm not drawing transparent, but I do draw transparent images on top of them, if that matters. Could you elaborate just what you mean? |
Dish
Posts: 157/596 |
If you're doing opaque blits... you might be able to perform this with 2 seperate BitBlt calls.. first using WHITENESS and next using SRCINVERT (instead of a single call using SRCCOPY).
I'm not sure how you'd go about it if you're doing transparent blits... at least... not without inverting the actual image (or making a copy and inverting the copy). |
HyperLamer
Posts: 1941/8210 |
I want to draw an inverted-colour version of an image, how can I do that? I normally just use BitBlt to draw it. (I'd prefer not having to modify the image itself.) |
|