I'm trying to repaint an image using the BrushTool possibilities. This way I can create a kind of cool graffiti effect. Scrolling over the 'brush' forum topics, I couldn't find an answer.
The code I'm currently using is based on program code to actually move the mouse between two points (I can't seem the mouse to continuously move over more than 2 points), while 'pressing' the left mouse button:
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: integer;
Pt, St: TPoint;
begin
{ Define the starting point = left-top corner of image 'RightImg' }
{ 10 pixels from the left-top edges }
St.x := RightImg.Left + 10;
St.y := RightImg.Top + 10;
{ draw 25 random brush lines within the boundaries of the image }
for j := 1 to 25 do
begin
{ required to draw one brush line }
for i := 1 to 2 do
begin
{ effectively 10 pixels from the right-bottom edges }
Pt.X := St.X + random(RightImg.Width - 20);
Pt.Y := St.Y + random(RightImg.Height - 20);
{ Convert Pt to screen coordinates relative to the 65535 mouse-steps across the screen }
Pt := ClientToScreen(Pt);
Pt.x := Round(Pt.x * (65535 / Screen.Width));
Pt.y := Round(Pt.y * (65535 / Screen.Height));
{ Simulate the mouse move }
Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_MOVE,
Pt.x, Pt.y, 0, 0);
{ Simulate the left mouse button down }
if i = 1 then Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_LEFTDOWN,
Pt.x, Pt.y, 0, 0);
{ Simulate the left mouse button up }
if i = 2 then Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_LEFTUP,
Pt.x, Pt.y, 0, 0);
end;
{ optional when 'Application.ProcessMessages' is used }
RightImg.Update;
{ optional: to watch the painting take place }
Application.ProcessMessages;
end;
end;
Additional settings to activate the BrushTool:
RightImg.BrushTool.BrushShape := iecsCircle;
RightImg.BrushTool.BrushFill := iebfTextured;
RightImg.BrushTool.BrushSize := 50;
RightImg.BrushTool.BrushColor := clRed;
RightImg.MouseInteract := [miBrushTool];
RightImg.BrushTool.PaintMode := iepmContinuous;
The code works fine, and I can see an animated brush drawing random lines.
However, I'd like to avoid the mouse events. When the application runs I don't like the idea of 'hijacking' the mouse for this effect. My preferred solution would be to use code to move the brush in the background, with no mouse interactions required, and then show it after a final refresh.
Can this be done?
Thanks for your support,
Sybren