From: Bee on
Is there an API that will do a color replace?
e.g. ReplaceColor picBox, vbRed, VbGreen
Not necessarily a call like this but this is the idea.
I need something faster than SetPixel, GetPixel
If not, is there some ASM code I can work into my VB6 app?

From: Larry Serflaten on

"Bee" <Bee(a)discussions.microsoft.com> wrote
> Is there an API that will do a color replace?
> e.g. ReplaceColor picBox, vbRed, VbGreen
> Not necessarily a call like this but this is the idea.
> I need something faster than SetPixel, GetPixel
> If not, is there some ASM code I can work into my VB6 app?

Have you searched google?

http://www.vbaccelerator.com/home/vb/tips/Replace_One_Colour_With_Another_in_a_Picture/article.asp

???


From: Bee on
Yeah, but I am not a Brit.
So I spell color correctly. lol
Thanks!


"Larry Serflaten" wrote:

>
> "Bee" <Bee(a)discussions.microsoft.com> wrote
> > Is there an API that will do a color replace?
> > e.g. ReplaceColor picBox, vbRed, VbGreen
> > Not necessarily a call like this but this is the idea.
> > I need something faster than SetPixel, GetPixel
> > If not, is there some ASM code I can work into my VB6 app?
>
> Have you searched google?
>
> http://www.vbaccelerator.com/home/vb/tips/Replace_One_Colour_With_Another_in_a_Picture/article.asp
>
> ???
>
>
> .
>
From: Martin Trump on
Bee wrote:
> Is there an API that will do a color replace?
> e.g. ReplaceColor picBox, vbRed, VbGreen
> Not necessarily a call like this but this is the idea.
> I need something faster than SetPixel, GetPixel
> If not, is there some ASM code I can work into my VB6 app?
>

The other answer here is probably the right one but there is a more
pedestrian way which has worked for me.

1. Read in a .bmp file in binary to a byte array
2. The first 54 bytes are the header. From that you can find the height
and width allowing access the colour info. Change that as you wish, save
it, then load it back into a PictureBox.

Three gotchas. The dimensions are stored LS byte first. Lines are padded
to a multiple of four bytes. The picture is stored upside down.

Just obtaining the colours from a 100k pixel image takes ~40msec on my
m/c. in the IDE, maybe twice as long for the complete colour replacement
job.

Martin