2

スクリーンショット (TBitmap) を取得するルーチンがあります。最終的な TBitmap/image にドロップ シャドウを追加する必要があります。このコードがあります (以前は機能していましたが...) 何かが正しくありません。ドロップ シャドウは単に描画されません:

// --------------------------------------------------------------------- //
procedure TakeScreenshot();
var
   lCapRect : TRect;
   DestBitmap : TBitmap;
begin
     // Take the screenshot & assign it to DestBitmap
     // ...

     // Add the drop shadow to DestBitmap
     DestBitmap.Width  := DestBitmap.Width + 6;
     DestBitmap.Height := DestBitmap.Height + 6;

     PaintShadow(DestBitmap.Canvas, lCapRect);
end;
// --------------------------------------------------------------------- //
procedure PaintShadow(ACanvas : TCanvas; ARect : TRect);
var
   AColor         : TColor;
   i, iMax        : Integer;
   h1, h2, v1, v2 : Integer;
begin
     AColor := ACanvas.Brush.Color;
     iMax   := 6;
     h1     := ARect.Left;
     h2     := ARect.Right;
     v1     := ARect.Top;
     v2     := ARect.Bottom;

     with ACanvas do
     begin
      for i := iMax downto 0 do
      begin
           ACanvas.Pen.Mode := pmMask;
           Pen.Color        := DarkenColorBy(AColor, ((iMax - i) * 4 + 10));

           MoveTo(h1 + 4{i}, v2 + i);
           LineTo(h2 + i + 1, v2 + i);
      end;    // for

      for i := iMax downto 0 do
      begin
           ACanvas.Pen.Mode := pmMask;
           Pen.Color        := DarkenColorBy(AColor, ((iMax - i) * 4 + 10));

           MoveTo(h2 + i, v1 + 4{i});
           LineTo(h2 + i, v2 + i);
      end;    // for
     end;    // with
end;
// --------------------------------------------------------------------- //
function Max(const A, B: Integer): Integer;
begin
     if (A > B) then
    Result  := A
     else
     Result := B;
end;
// --------------------------------------------------------------------- //
function DarkenColorBy(BaseColor : TColor; Amount : Integer) : TColor;
begin
     Result := RGB(Max(GetRValue(ColorToRGB(BaseColor)) - Amount, 0),
           Max(GetGValue(ColorToRGB(BaseColor)) - Amount, 0),
           Max(GetBValue(ColorToRGB(BaseColor)) - Amount, 0));
end;

私の質問は次のとおりです。これを修正するにはどうすればよいですか (または、ドロップシャドウを TBitmap に追加する簡単な方法を知っている人がいます)。

最終的な画像は bmp/jpg として保存され、TImage には表示されないため、画像自体にドロップ シャドウを追加する必要があります。

PS。Delphi 7 Pro を使用しています。アプリは Windows XP 以降に制限されています

編集

lCapRectは設定 (アクティブなモニター、ウィンドウ、またはすべてのデスクトップ モニターをキャプチャしているかどうか) によって異なりますが、次のように計算されるとしましょう。

lCapRect.Right  := Screen.DesktopLeft + Screen.DesktopWidth;
lCapRect.Bottom := Screen.DesktopTop + Screen.DesktopHeight;
lCapRect.Left   := Screen.DesktopLeft;
lCapRect.Top    := Screen.DesktopTop;

ビットマップにはスクリーンショットが含まれています (+ 6 ピクセルが下と右側に追加され、ドロップ シャドウ用のスペースが確保されます)。ドロップ シャドウの描画が行われないだけです。

4

1 に答える 1

3

You haven't shown how you are calculating lCapRect. For not drawing off the bitmap regarding your PaintShadow procedure, it has to be smaller than the bitmap, example:

lCapRect := DestBitmap.Canvas.ClipRect;

// Add the drop shadow to DestBitmap
DestBitmap.Width  := DestBitmap.Width + 6;
DestBitmap.Height := DestBitmap.Height + 6;

PaintShadow(DestBitmap.Canvas, lCapRect);
于 2012-06-06T17:46:40.110 に答える