ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 SelectColors help
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Jan 04 2014 :  02:11:25  Show Profile  Reply
I use SelectColors to select a known color using CreateRGB. I would like to know how to do the following:

1. Either replace the selected color with another color

2. Or, Copy and paste to create another bitmap of the selected color

Thank you in advance.

w2m

USA
1990 Posts

Posted - Jan 04 2014 :  07:06:09  Show Profile  Reply
Did you try CastColorRange or CastColor?


TImageEnProc.CastColorRange

Declaration

procedure CastColorRange(BeginColor, EndColor, CastColor: TRGB);

Description
Use this method to force all colors included in the range BeginColor and EndColor to be equal to CastColor.

Example
// Force to black all gray levels from 50 to 100
var
  BeginColor, EndColor, CastColor:TRGB;
begin
  BeginColor:=CreateRGB(50,50,50);
  EndColor:=CreateRGB(100,100,100);
  CastColor:=CreateRGB(0,0,0);
  ImageEnView1.Proc.CastColorRange(BeginColor,EndColor,CastColor);
end;


TImageEnProc.CastColor

Declaration

procedure CastColor(x, y: Integer; newColor:TRGB; tolerance: Integer);

Description

Performs a flood-fill starting at x, y coordinates. newColor is the color used to paint.
tolerance specifies the maximum difference from the starting pixel (0=no tolerance, pixels must be equals).

Example

// assuming X,Y = mouse coordinates, paints points to red
ImageEnView1.Proc.CastColor(ImageEnView1.XScr2Bmp(X), ImageEnView1.Yscr2Bmp(Y), CreateRGB(255,0,0), 0);


William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Jan 05 2014 :  03:51:26  Show Profile  Reply
Hello William,

Thank you for the code. I will give it a try.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Jan 11 2014 :  21:13:57  Show Profile  Reply
Hello William, how do I use CastColorRange with the sample image if I want to change the pink color to white to match the background white? I can't seem to be able to determine the color range for the pink. Thanks for your help.

Go to Top of Page

w2m

USA
1990 Posts

Posted - Jan 12 2014 :  07:42:51  Show Profile  Reply
The "pink" colors are many shades of "pink", so CastColorRange does not work well in this situation. You should try to use CastColor with various tolerance values to replace the colors. By using undo you can reset and try another tolderance value until you get the colors converted that are acceptable. I find that it is difficult to fill a gradient with a color because there are so many shades. It would be nice if ImageEn had a method that could replace all shades of "pink" to a different color... something like ReplaceAllShadesOfAColor(AColor: TColor; ANewColor: TColor), but there is no such function. The best you can do at the moment is to use CastColor unless someone knows how to get the first shade of "pink" and the last shade of "pink". Unfortunately I do not how to get the starting and ending shade.

I have a small demo that shows how to use castcolor to replace the "pink" colors. Send me your email and I'll send you the demo.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: