Add TBitmap to Layout

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: admin, support, SDS

Post Reply
KKesslau_SEMA
Posts: 5
Joined: 09 Mar 2018, 14:43

Add TBitmap to Layout

Post by KKesslau_SEMA » 09 Mar 2018, 14:54

Hi,

how can I add a TBitmap to a Layout? I found the Entity TsgDXFImageEnt, but with which properties can I set the position/size/etc.? I looked in your CAD VCL Help, but I can't figure it out. Can you give me an example?
Thanks in advance.

Kevin

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: Add TBitmap to Layout

Post by support » 13 Mar 2018, 20:50

Hello Kevin,

To add a bitmap on CAD layout, you need to create a TsgDXFImageDef entity from a specified raster image file (.bmp, for instance), and then add a new TsgDXFImageEnt entity based on this TsgDXFImageDef. To set a position and size of TsgDXFImageEnt, you can use TsgDXFImageEnt.Point and TsgDXFImageEnt.Size properties.

The following code snippet demonstrates how to implement the above said.

Code: Select all

uses
  ..., SysUtils, CADImage, DXFConv, sgConsts;

...

FCADImage: TsgCADImage;

...

implementation

{$R *.dfm}

...

function CreateImageDef(ACADImage: TsgCADImage; const AFileName: string): TsgDXFImageDef;
begin
  Result := TsgDXFImageDef.Create;
  Result.FileName := AFileName;
  ACADImage.Converter.Sections[csImageDefs].AddEntity(Result);
  if Assigned(ACADImage.Converter.OnCreate) then
    ACADImage.Converter.OnCreate(Result);
  ACADImage.Converter.Loads(Result);
end;

function AddImageEnt(ATargetImage: TsgCADImage; const ALayoutName, AImageFileName: string; APosition: TFPoint; AWidth, AHeight: TsgFloat): TsgDXFImageEnt;
var
  vLayout: TsgDXFLayout;
begin
  if not Assigned(ATargetImage) or not FileExists(AImageFileName) then Exit;
  Result := TsgDXFImageEnt.Create;
  Result.ImageDef := CreateImageDef(ATargetImage, AImageFileName);
  Result.Point := APosition;
  Result.Size := MakeFPoint(APosition.X + AWidth, APosition.Y + AHeight, 0);
  vLayout := ATargetImage.Converter.LayoutByName(ALayoutName);
  if Assigned(vLayout) then
  begin
    vLayout.AddEntity(Result);
    if Assigned(ATargetImage.Converter.OnCreate) then
      ATargetImage.Converter.OnCreate(Result);
    ATargetImage.Converter.Loads(Result);
    ATargetImage.GetExtents;
  end;
end;

...

AddImageEnt(FCADImage, 'Layout1', 'c:\image.bmp', MakeFPoint(100, 100, 0), 200, 200);
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

KKesslau_SEMA
Posts: 5
Joined: 09 Mar 2018, 14:43

Re: Add TBitmap to Layout

Post by KKesslau_SEMA » 14 Mar 2018, 12:15

Hello Mikhail,

thanks for the code snipped, worked like a charm :)

Kevin

Post Reply