I don't think there is a way around your problem because CastColor casts the pixel color biased on the colors around the cursor point and the tolerance value... so the key to figure this out is what colors to I want to allow filling?
If your backbround color is clWhite or some other specific color then you can get the color under the pixel with
iColorUnderCursor := TRGB2TColor(ImageEnView1.Layers[ImageEnView1.LayersCurrent].Bitmap.Pixels[BX, BY]);
if iColorUnderCursor <> clWhite then
begin
ImageEnView1.Proc.CastColor(AX, AY, TColor2TRGB(clRed), 10);
end
else
begin
ShowMessage('The color being cast is white. Can not cast white colors.');
end;
This of course will not permit filling inside the rectangle if the colors inside the rectangle is White. If the color under the mouse can be any color then this will not work of course and I do not know of a another way to proceed.
You can also draw your rectangle with a solid brush which would eliminate the need to castcolor all together. This is probably the best way to proceed, but your explanation does not describe enough of what you are trying to do to try to determine another approach.
I hope this helps.
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html