我可以在不失效的情況下找到所有GDIPlus演示代碼。那麼,如何在TScrollbox上使用帶有TImage的MouseMove進行繪製時,如何使GDIPlus API中的矩形無效?如何使用GDIPlus進行InvalidateRect
function NormalizeRect (R: TRect): TRect;
begin
// This routine normalizes a rectangle. It makes sure that the Left,Top
// coords are always above and to the left of the Bottom,Right coords.
with R do
begin
if Left > Right then
if Top > Bottom then
Result := Rect (Right, Bottom, Left, Top)
else
Result := Rect (Right, Top, Left, Bottom)
else if Top > Bottom then
Result := Rect (Left, Bottom, Right, Top)
else
Result := Rect (Left, Top, Right, Bottom);
end;
end;
procedure TFormMain.Image1MouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Line1.Down then
begin
GPPointStart := MakePoint (X, Y);
end;
end;
procedure TFormMain.Image1MouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
graphics: TGPGraphics;
pen: TGPPen;
SolidBrush: TGPSolidBrush;
rgbTriple: windows.RGBTRIPLE;
iRect: TRect;
begin
if Line1.Down then
begin
if ssLeft in Shift then
begin
iRect := NormalizeRect (Rect (X, Y, Image1.Picture.Bitmap.Width, Image1.Picture.Bitmap.Height));
InvalidateRect (ScrollBox1.Handle, @iRect, TRUE);
graphics := TGPGraphics.Create (Image1.Picture.Bitmap.Canvas.Handle);
graphics.Flush (FlushIntentionFlush);
GPPointEnd := MakePoint (X, Y);
rgbTriple := ColorToRGBTriple (ColorBox1.Selected);
pen := TGPPen.Create (MakeColor (StrToInt (Alpha1.Text), rgbTriple.rgbtRed, rgbTriple.rgbtGreen, rgbTriple.rgbtBlue)
);
pen.SetWidth (StrToInt (Size1.Text));
graphics.DrawLine (pen, GPPointStart.X, GPPointStart.Y, GPPointEnd.X, GPPointEnd.Y);
graphics.Free;
Image1.Refresh;
end;
end;
end;
這是什麼樣子:
使用GDIPlus圖書館從http://www.progdigy.com與2010年德爾福
感謝您的回答。我明白你在告訴我什麼,但我仍然不知道如何解決它。還有什麼建議? – Bill 2012-04-11 21:00:33
不是繪製到位圖,而是繪製到滾動框。這使得位圖不受影響。使舊線區失效。刷新以在舊線上繪製圖像。然後畫出新的線。如果您需要更多幫助,請提出一個關於您真正想要做什麼的新問題。 – 2012-04-11 21:14:44
@Rob,*不是繪製到位圖,而是繪製到滾動框*,「TScrollBox」沒有可以繪製的畫布。當你考慮內容滾動時,它甚至不是一個好主意。我想你的意思是*而不是繪製到圖像,繪製到位圖*不是嗎? – TLama 2012-04-11 22:47:48