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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Color Replacement limitation to Selection area?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Dec 11 2022 : 09:29:35
I replace a specific color in the image with this code:

procedure TformMain.ButtonDoReplaceColorClick(Sender: TObject);
begin
  ImageEnViewPixelEditor.Proc.CastColorRange(
  TColor2TRGB(PanelReplaceColorsPickedColor.Color), // OldColor
  TColor2TRGB(PanelReplacementColor.Color),         // NewColor
  TrackBarColorReplacementTolerance.Position);      // Tolerance
end;


Now I would like to limit the replacement to the area inside the current selection (if any). How could this be done?
6   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Dec 13 2022 : 10:52:40
Hi Nigel,

Thank you for the information and your support.
xequte Posted - Dec 12 2022 : 18:43:45
Hi Peter

All TImageEnProc methods are limited to the selection. If there is not selection they apply to the whole image. I'll add more detail on this to the documentation.

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Dec 12 2022 : 01:15:09
Unfortunately, the ImageEn.chm documentation does not explicitly mention the selection restriction of CastColorRange.
xequte Posted - Dec 11 2022 : 20:23:21
Hi

CastColorRange() should already respect the selection (see the demo: \ImageEding\EveryMethod\EveryMethod.dpr).

Can you give me more detail of when this is not occurring?

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Dec 11 2022 : 16:21:55
UPDATE: This is an improved and simplified version of the code above:

// Create the TIEBitmap to hold the selection:
var ThisIEBitmap := TIEBitmap.Create;
try
  // Copy the selection to the ThisIEBitmap:
  ImageEnView1.CopySelectionToIEBitmap(ThisIEBitmap);

  var proc := TImageEnProc.CreateFromBitmap(ThisIEBitmap);
  try
    proc.CastColorRange(
      TColor2TRGB(PanelReplaceColorsPickedColor.Color), // OldColor
      TColor2TRGB(PanelReplacementColor.Color),         // NewColor
      cxTrackBarColorReplacementTolerance.Position);    // Tolerance

    // Copy the ThisIEBitmap to the main ImageEnView:
    ImageEnView1.ApplyBitmapToSelection(ThisIEBitmap);
  finally
    proc.Free;
  end;
finally
  ThisIEBitmap.Free;
end;


This code eliminates the unnecessary step of copying the TIEBitmap to another ImageEnView just to replace the color, and then copying it back to the main ImageEnView. It instead directly replaces the color in the TIEBitmap, and then applies it to the selection in the main ImageEnView. This reduces the amount of memory and processing needed, and makes the code more efficient.

REMARKS: This shows how I have done it in my app:

My UI: https://app.screencast.com/3ec9XA218baui

Image without selection: https://app.screencast.com/89ulS63WG8dr2

Image WITH selection: https://app.screencast.com/pUGCsd9wYLHNm

PeterPanino Posted - Dec 11 2022 : 10:28:06
I have created a solution to solve the problem:

if ImageEnView1.Selected then // if a selection exists
begin
  var ThisIEBitmap: TIEBitmap;
  // Create the TIEBitmap to hold the selection:
  ThisIEBitmap := TIEBitmap.Create;
  try
    // Copy the selection to the ThisIEBitmap:
    ImageEnView1.CopySelectionToIEBitmap(ThisIEBitmap);
    // Copy the ThisIEBitmap to another ImageEnView:
    ImageEnViewDummy.IEBitmap.Assign(ThisIEBitmap);
  finally
    ThisIEBitmap.Free;
  end;
  // Replace the color in the other ImageEnView:
  ImageEnViewDummy.Proc.CastColorRange(
    TColor2TRGB(PanelReplaceColorsPickedColor.Color), // OldColor
    TColor2TRGB(PanelReplacementColor.Color),         // NewColor
    cxTrackBarColorReplacementTolerance.Position);    // Tolerance
  // Copy the IEBitmap from the other ImageEnView to the selection in the main ImageEnview:
  ImageEnView1.ApplyBitmapToSelection(ImageEnViewDummy.IEBitmap);
end;


Here is an example result:

https://app.screencast.com/GRz84SmkdhZkw

Can this solution be simplified and improved?