在图层中绘制透明椭圆

时间:2013-08-24 12:23:06

标签: delphi layer graphics32

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

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

1 个答案:

答案 0 :(得分:5)

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

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;