On Nov 21, 1:02 pm, "Michael Phillips, Jr."
[quoted text, click to view] <mphillip...@nospam.jun0.c0m> wrote:
> > 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...@gmail.com> wrote in message
>
> news:8321fbdf-295a-4f7b-8a65-3eedac462248@w34g2000hsg.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
Michael, thank you for your answer. The problem is that I am using a
ported version of the NET classes in VFP. I tried doing what you
suggest, before reading your post, but that is terribly slow in VFP.
I came up with an alternative, but does not work as I expect.
I want to try to draw the original image to a bitmap, then in the mask
image do a RemapTable of Black to Trasparent, and draw that on top of
the former.
My asumption is that will result in what I want. Now the problem is
that I cant change black to transparent! I do a test:
(Syntax is VFP, but readable)
m.loMask1 = .Bitmap.New(m.lcFileName)
m.loMask2 = .Bitmap.New(m.loMask1.Width, m.loMask1.Height,
0, .Imaging.PixelFormat.Format32bppRGB)
m.loGraphics = .Graphics.FromImage(m.loMask2)
m.loGraphics.Clear(.Color.Transparent)
m.loColorMap = .Imaging.ColorMap.New()
m.loAttributes = .Imaging.ImageAttributes.New()
m.loColorMap.OldColor = .Color.Black
m.loColorMap.NewColor = .Color.Transparent
m.loAttributes.SetRemapTable(m.loColorMap)
m.loGraphics.DrawImage(m.loMask1, m.loRect,
m.loRect, .GraphicsUnit.Pixel, m.loAttributes)
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:
m.loColorMap.OldColor = .Color.FromArgb(255,0,0,0)
m.loColorMap.NewColor = .Color.FromArgb(128,255,0,255)
Does not turn Black pixels to ARGB(128,255,0,255) but to
ARGB(255,128,0,128) !!
It seems the Alpha value is premultipled and applied to the RGB
values.
Is that the standard behaviour in .NET or should I be getting
ARGB(128,255,0,255)?
Thank you very much for your time and patience.