delphi - 在图层中绘制一个透明的椭圆

标签 delphi layer graphics32

我的表单上有一个 TImgView32(名为 CityMap),并在其上加载了图像。现在,我创建一个图层 (TBitmapLayer) 并使用 TBitmap32 变量的 Canvas.Ellipse 绘制一个圆,如下所示:

procedure TfrmMain.Button1Click(Sender: TObject);
var
  tmpBmp: TBitmap32;
  tmpBL: TBitmapLayer;  
begin
  tmpBL:= TBitmapLayer.Create(CityMap.Layers);

  tmpBmp:= TBitmap32.Create;

  with tmpBmp do
  begin
    //Clear;
    SetSize(50, 50);
    Canvas.Brush.Color := clYellow;
    Canvas.Brush.Style:= bsSolid;
    Canvas.Pen.Color := clBlue;
    Canvas.Pen.Width := 2;
    Canvas.Ellipse(Rect(0, 0, 50, 50));
  end;  

  with tmpBL do
  begin
    Scaled:=true;
    Bitmap.DrawMode:=dmBlend;
    tmpBL.Bitmap:=(tmpBmp);
    //tmpBmp.DrawTo(tmpBL.Bitmap, 0, 0); This line doesn't work! So using above line instead
  end;

  //...

end;

结果是这样的:

Current result

如您所见,问题在于那个烦人的黑色矩形。如何创建这样的结果:

desired result

最佳答案

TBitmap32 图像的 DrawMode 属性使用 dmTransparent 绘制模式:

procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap: TBitmap32;
  Layer: TBitmapLayer;
begin
  Layer := TBitmapLayer.Create(CityMap.Layers);

  Bitmap := TBitmap32.Create;
  Bitmap.DrawMode := dmTransparent;
  Bitmap.SetSize(50, 50);
  Bitmap.Canvas.Brush.Color := clYellow;
  Bitmap.Canvas.Brush.Style:= bsSolid;
  Bitmap.Canvas.Pen.Color := clBlue;
  Bitmap.Canvas.Pen.Width := 2;
  Bitmap.Canvas.Ellipse(Rect(0, 0, 50, 50));

  Layer.Scaled := True;
  Layer.Bitmap := Bitmap;
  ...
end;

关于delphi - 在图层中绘制一个透明的椭圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18418513/

相关文章:

delphi - Firemonkey - 更新视觉组件

delphi - 在工作线程中使用 SHFileOperation 是否安全?

Delphi7 - 如何复制正在写入的文件

CSS - 弹出层(带有覆盖和关闭按钮)

delphi - GIF动画TImage/Timage32

delphi - 隐藏 TActionMainMenuBar?

python - 指定层的顺序

Java 小程序 : is there a simple way to draw and erase in a two-layered 2D scene?

delphi - 将 ImgView32 透明图层保存为 PNG

delphi - Graphics32 用阴影图案填充多边形