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
 Area that should be white - Microsoft Picture Manager
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Waheed

Kuwait
35 Posts

Posted - Aug 30 2021 :  13:13:42  Show Profile  Reply
There is a feature in Microsoft Picture Manager 2010 where it replaces an color from the selected pixel/s color to white.

The tool looks like this, when I press on the button the screen cursor changes to a cross-hair


Then I click on the picture (here is a sample of the before)



(and the sample after)



How can I do that in ImageEn?
Here is my efforts which didn't work as expected, colors inside enclosed areas are not made white:

procedure TfrMain.btnCastColorClick(Sender: TObject);
begin
   CastColorOn := True;
   Screen.Cursor := crCross;
end;

procedure TfrMain.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   fMouseDownX := X;
   fMouseDownY := Y;
end;

procedure TfrMain.Image1Click(Sender: TObject);
begin
   if CastColorOn then begin
      // it took a long time for the operation to complete compared to Microsoft method
      Image1.Proc.CastColor(Image1.XScr2Bmp(fMouseDownX), Image1.Yscr2Bmp(fMouseDownY), CreateRGB(255, 255, 255), 10); 
      CastColorOn := False;
      Screen.Cursor := crDefault;
   end;
end;



Here is the sample image.
attach/Waheed/202183013381_sample.zip
647.81 KB
-----------------
3 Monitors
Windows 10
Delphi 6,2007 and 10.2
ImageEn v.10.0.1

xequte

6332 Posts

Posted - Aug 30 2021 :  18:29:52  Show Profile  Reply
Hi Waheed

CastColor performs a flood fill. You want to use CastColorRange which processes all pixels in the image.


procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
const
  Tolerance = 10;
var
  clickColor, fromRGB, toRGB: TRGB;
begin
  // When the user clicks the image turn all image pixels of a similar color to white
  if fColorCasting then
  begin
    clickColor := ImageEnView1.IEBitmap.Pixels[ ImageEnView1.XScr2Bmp(x), ImageEnView1.Yscr2Bmp(y) ];

    fromRGB := CreateRGB( imax( 0, clickColor.r - Tolerance ),
                          imax( 0, clickColor.g - Tolerance ),
                          imax( 0, clickColor.B - Tolerance ));
    toRGB   := CreateRGB( imin( 255, clickColor.r + Tolerance ),
                          imin( 255, clickColor.g + Tolerance ),
                          imin( 255, clickColor.B + Tolerance ));

    ImageEnView1.Proc.CastColorRange( fromRGB, toRGB, CreateRGB(255, 255, 255));
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Waheed

Kuwait
35 Posts

Posted - Aug 30 2021 :  22:49:36  Show Profile  Reply
Great. Thanks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: