![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
BITMAP1: COLOR X + BITMAP2: BLACK = COLOR X BITMAP1: COLOR X + BITMAP2: WHITE = WHITE How could I do this? |
|
I need to combine two 24bpp bitmaps. The mask bitmap only has two values for its pixels: black or white. The combined resulting bitmap should be: BITMAP1: COLOR X + BITMAP2: BLACK = COLOR X BITMAP1: COLOR X + BITMAP2: WHITE = WHITE How could I do this? Carlos Alloatti |
#3
| |||
| |||
|
|
BITMAP1: COLOR X + BITMAP2: BLACK = COLOR X BITMAP1: COLOR X + BITMAP2: WHITE = WHITE How could I do this? 1) Create a new destination 24bpp bitmap and use Graphics.DrawImage to copy the source bitmap to the destination. 2) Use LockBits with read/write access in a loop to cycle through all of the destination pixels. And cycle through all of the mask pixels in the same loop. The mask bitmap should be locked with read access only. 2) Test the mask pixel's color. If black, do nothing to the destination's pixel. If the mask color is white, then change the color of the destination pixel to white. 3) Unlock both bitmaps, save the new destination bitmap and your done! "Carlos Alloatti" <calloa... (AT) gmail (DOT) com> wrote in message news:8321fbdf-295a-4f7b-8a65-3eedac462248 (AT) w34g2000hsg (DOT) googlegroups.com... I need to combine two 24bpp bitmaps. The mask bitmap only has two values for its pixels: black or white. The combined resulting bitmap should be: BITMAP1: COLOR X + BITMAP2: BLACK = COLOR X BITMAP1: COLOR X + BITMAP2: WHITE = WHITE How could I do this? Carlos Alloatti |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
|
"With that code, nothing happens, I just get the same image again, so I did some tests, using for example: m.loColorMap.OldColor = .Color.Black m.loColorMap.NewColor = .Color.Transparent Gives me what I expect, Black pixels turn to Magenta. Now doing for example:" Should be: "With that code, nothing happens, I just get the same image again, so I did some tests, using for example: m.loColorMap.OldColor = .Color.Black m.loColorMap.NewColor = .Color.MAGENTA Gives me what I expect, Black pixels turn to Magenta. Now doing for example:" |
|
... I tried doing what you suggest, before reading your post, but that is terribly slow in VFP. |
|
Sorry in the previous post, "With that code, nothing happens, I just get the same image again, so I did some tests, using for example: m.loColorMap.OldColor = .Color.Black m.loColorMap.NewColor = .Color.Transparent Gives me what I expect, Black pixels turn to Magenta. Now doing for example:" Should be: "With that code, nothing happens, I just get the same image again, so I did some tests, using for example: m.loColorMap.OldColor = .Color.Black m.loColorMap.NewColor = .Color.MAGENTA Gives me what I expect, Black pixels turn to Magenta. Now doing for example:" Carlos Alloatti |
#7
| ||||
| ||||
|
|
Perhaps, I misunderstood your post. I thought that you were working with 24bpp bitmaps. |
|
If so, then there is no alpha component to the color remapping. For 32bpp alpha channeled bitmaps, the alpha component is premultiplied for performance and/or because a particular graphic's operation may require that the alpha channel be premultiplied to work correctly. If you wish to promote your 24bpp bitmap to 32bpp ARGB, then you could try remapping the transparent color with SetColorKey. This is what I use. It is very convenient to specify a range representing a min and max key color and remap to a transparent color with one method call. ... I tried doing what you suggest, before reading your post, but that is terribly slow in VFP. Lockbits is slow for Read/Write access because a temporary buffer is created and then written back when unlocked. Performance is predicated on how fast your system Marshals between managed and unmanaged code. |
|
For Read access only on the mask bitmap, the speed will should be fast as no temporary buffer is created. To speed things up, you could try to use GDI ROP with P-Invoke. Using BitBlt with SRCAND will allow you to punch out your source image with the AND operation. This is very fast, and you may use a monochrome bitmap with two colors instead of a 24bpp bitmap with two colors. If you load and create your color bitmap as a DIB then you have direct access to the memory. Cycling through and remapping the rest of the pixels will be very fast. I have not used VFP so I do not know if P-Invoke is possible. |
| Thanks again, |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |