1

I have a TImgView32(named CityMap) on my form and an image is loaded on it. Now I create a layer(TBitmapLayer) and draw a circle using Canvas.Ellipse of a TBitmap32 variable like the following:

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;

The result is like this:

Current result

As you see the problem is that annoying black rectangle. How to create a result like this:

desired result

SAMPro
  • 1,068
  • 1
  • 15
  • 39

1 Answers1

5

Use dmTransparent draw mode for the DrawMode property of your TBitmap32 image:

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;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • Anyway, if you were looking for an antialiased vector drawing engine, I would suggest you the Anti Grain Geometry Library (AGG). I have tried e.g. the GR32_Lines extension when I was deciding what we use in our map control, which I'm working on, but the results were not as good as from AGG. And, just out of curiosity, AGG is used as a prime renderer for Mapnik, which is used e.g. for rendering the OpenStreetMaps tiles. – TLama Aug 24 '13 at 14:44
  • Thanks for your information. Same as you I have tried GR32_Lines to produce anti-aliased result. But it has a bad effect when zooming the map. Anyway GR32 has great features(Layers and transformations for example). Can I use AGG with GR32(IDK anything about AGG)? – SAMPro Aug 25 '13 at 04:23
  • I'm personally using the [`AggPasMod`](http://sourceforge.net/projects/aggpasmod/) wrapper, which comes with a [`GR32 demo`](http://sourceforge.net/p/aggpasmod/code/39/tree/trunk/Examples/VCL/Agg2D%20%28GR32%29/). I didn't tried that demo, but for sure I can tell you that you can work with AGG as with a `TGraphic` object (`TAgg2DGraphics`), so you can render the vector results e.g. with the `TCanvas.Draw` method. – TLama Aug 25 '13 at 06:27
  • Does it can paint itself so when Bimap32 image is scaled(through e.g ImgView32) it produce anti grain results(with `Layer.Scaled := True;`)? – SAMPro Aug 26 '13 at 04:46
  • I think there's a way to do so, but haven't ever used it. We're using AGG more as a raster renderer beacause when our map is zoomed (we're using only fixed zoom values given by our OSM tile server renderer), the route highlights and all related custom points are re-rendered because the points get more accurate position on the map if it's zoomed in or zoomed out. I know it's not your case, but I can't serve here. – TLama Aug 26 '13 at 06:33
  • I think maybe the other way is calculating position and size of layers based on the zoom level(with `Layer.Scaled := False;`) When OnMouseMove (or `OnPaintStage` maybe). But I think it's better to search if this is already done by GR32. – SAMPro Aug 26 '13 at 13:40
  • I can't serve here since we are using [`fixed equation`](http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Pascal) for our points position rendering, so I didn't used AGG scaling (though I know it supports various transformations). – TLama Aug 26 '13 at 13:47
  • I would love to test that AggPasMod in my Delphi XE, but unfortunately, the demo must have been built for bigger versions, because after I installed the package, when trying to run the demo from GR32, I get `vcl.forms.dcu file not found` error. So I cannot compile it – user1137313 Feb 16 '15 at 13:09
  • @user1137313, then either add the `vcl` namespace to the unit scope names (in the project options), or just remove `vcl.` namespace prefix from the unit name in all the unit/project `uses` clauses. You will meet similar problems with other units as well. – TLama Feb 16 '15 at 13:14
  • Thanks TLama, I just figured it out myself when I looked at the project source. I removed Vcl.Forms and replaced it with just Forms. Thank you for your quick response. Do you think you can take a look at this question too: http://stackoverflow.com/questions/28534892/delphi-graphics32-transparent-layer-draw-line ? Any help is greatly appreciated – user1137313 Feb 16 '15 at 13:24