Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change all pixels = red into blue, *really fast*

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I've been looking high and low, for a image manipulation code, that could, if I gave it an RGB I wanted it to replace with a second RGB, and it has to do it fast, not spend 30 seconds, searching every pixel and chaging them as they go. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Karl,

AFAIK this needs to be different for various graphic types. Given that one 'knew' the encoding for the specific graphic type, one might need up do an un-pack process before the replacement.

The actual process/function is just an itterative search and replace.

Long awat and far ago (in the days of DOS) there was a commercially available publication which gave the schemes used to encode the more common graphics endcoding schemes. I have long since lost my copy (I think it went with my son?) As I recall, there were over 200 different schemes at that time, some with numerours variations.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
I really have no clue what you meant to say by that, but in any case there isnt really a "Graphic" type, or "Unpacking" required, because the images is being generated by the program, I just need something to change a color in the picturebox to another color, without looping and using setpixel which takes too long. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
You can simply change the RGB value in the palette section. I am thinking of a 256 color PCX with RLE compression. If palette index 70, for example, has an RGB value of 255-100-45, you can modify the value of 70 to 100-30-120. Because 70 is just an index number, you won't have to modify every pixel in the file.

As far as modifying the colors once they are on the screen... in DOS it was easy; just modify the VGA palette and the screen would update instantly (on the next vertical retrace). There is probably an API function to modify a palette in Windows to have the same affect.
Rob Marriott
rob@career-connections.net
 
ok , let me repeat myself, I am not loading an image file, but rather painting to a picturebox, how in a PICTUREBOX, in Visual Basic (not DOS), do I change all pixels on the picture box, matching one color, into another, with very fast speeds, not scrolling from left/right top/bottom slowely like when you loop using GetPixel and SetPixel Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
If THATS all you want, just include a second hidden picture box. Copy the original to the second with Picture.PaintPicture. The last arg is the one which specifies the process used to 'mask' the two images. For instance, if the second picture box is a specific color (All RED), you can mask the original image with the 'COLOR" in various ways.

Do the transform and swap the two picture boxes.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
um, the choice of color to replace is going to depend on the situation, like it may not be red all the time that I want to replace, and blue might not be the color that I am replacing the selected with, so it still has to be dynamic, rather than creating a static mask, especially since the images are auto-generated.

the idea behind this, is that you have a image, several pixels on the images, are closely colored, but not exactly the same, so.... , lets say you want to show the location for all firms, for such and such companies, and you identified, that it is like 2 Green values above the background color(dark green) , you tell it you want to replace all the specific green color for that bit of data with , red for example, Thus you have all the locatoins pinpointed without making a roundtrip to the server, and without re-rendering the image to plot the points. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
KARL,

Please look at the PaintPicture thing. It works quite well for what you describe. The Logical MAske work with the existing destination image, including the BACKGROUNS and FOREGROUND Colors. Just clear the (second) picturebox and SET its .backcolor SrcPaintPicture dest ... Op (Op is the last arg). Figure out wheather you want to [AND | OR | XOR ... ] the results to get the results you want.

Selection of colors and op may be a tricky exercise until you get the hang of it.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top