無効にすることなく描画できるGDIPlusのデモコードはすべてあります。だからTScrollbox上でMouseMoveでTImageを使用して描画するとき、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;
これは、次のようになります。デルファイ2010にhttp://www.progdigy.comからGDIPlusのライブラリを使用して
答えをありがとう。私はあなたが私に言っていることを理解していますが、それを修正する方法はまだ分かりません。それ以上の助言? – Bill
ビットマップに描画する代わりに、スクロールボックスに描画します。そのため、ビットマップは変更されません。古い行領域を無効にします。画像を古い線の上に塗りつぶすために更新します。次に、新しい行を描画します。より多くの助けが必要な場合は、あなたが本当にやろうとしていることについて新しい質問をしてください。 –
@Rob、*ビットマップに描画する代わりにスクロールボックス*に描画すると、 'TScrollBox'にはペイントできるキャンバスがありません。コンテンツのスクロールを考慮すると、それは良い考えではありません。私はあなたがイメージを描く代わりにビットマップに描くのではなく、あなたが*を意味すると思います*あなたはありませんか? – TLama