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.
Posted - Dec 11 2022 : 16:21:55UPDATE: 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.
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;