如何在完整的位图图像中绘制阴影效果? [英] How draw a shadow effect in a complete Bitmap image?

查看:139
本文介绍了如何在完整的位图图像中绘制阴影效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在已经存在的完整位图图像中绘制阴影效果,并且在具有类似于以下示例的效果之后,模态窗体后面的所有区域都是我的新位图图像已经具有阴影效果了吗? =>

I want know if is possible draw a shadow effect in a complete Bitmap image already existent and after have a effect similar to this example below, where all area behind modal Form is my new Bitmap image already with the shadow effect? =>

推荐答案

这很容易。首先,我们需要一个使给定位图褪色的例程:

This is pretty easy. First we need a routine that fades a given bitmap:

procedure FadeBitmap(ABitmap: TBitmap);
type
  PRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = array[word] of TRGBTriple;
var
  SL: PRGBTripleArray;
  y: Integer;
  x: Integer;
begin
  ABitmap.PixelFormat := pf24bit;

  for y := 0 to ABitmap.Height - 1 do
  begin
    SL := ABitmap.ScanLine[y];
    for x := 0 to ABitmap.Width - 1 do
      with SL[x] do
        begin
          rgbtRed := rgbtRed div 2;
          rgbtGreen := rgbtGreen div 2;
          rgbtBlue := rgbtBlue div 2;
        end;
  end;
end;

然后,当我们要显示模态消息时,我们会为当前图像创建位图屏幕快照窗体,使其褪色,并将其放在窗体的所有控件之上:

Then, when we want to display our modal message, we create a bitmap 'screenshot' of our current form, fade it, and place it on top of all controls of the form:

procedure TForm1.ButtonClick(Sender: TObject);
var
  bm: TBitmap;
  pn: TPanel;
  img: TImage;
begin

  bm := GetFormImage;
  try
    FadeBitmap(bm);

    pn := TPanel.Create(nil);
    try
      img := TImage.Create(nil);
      try
        img.Parent := pn;

        pn.BoundsRect := ClientRect;
        pn.BevelOuter := bvNone;
        img.Align := alClient;

        img.Picture.Bitmap.Assign(bm);

        pn.Parent := Self;

        ShowMessage('Hello, Faded Background!');

      finally
        img.Free;
      end;
    finally
      pn.Free;
    end;
  finally
    bm.Free;
  end;

end;

提示:如果您的应用程序中要显示多个模式对话框,则可能需要对其进行重构。为此,请查看 TApplicationEvent OnModalBegin OnModalEnd 事件。

Hint: If you have more than one modal dialog to display in your application, you probably want to refactor this. To this end, have a look at TApplicationEvent's OnModalBegin and OnModalEnd events.

这篇关于如何在完整的位图图像中绘制阴影效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆