Page 1 of 1

Embed images into DXF file

Posted: 19 Feb 2014, 23:31
by jose_olalla
Hello.
I am using the entitiesTsgDXFImageDef and TsgDXFImageEnt to include images into my code generated DXF file. But when I save the DXF the images are saved as refX (External references) and my clients cannot view this images. (Autocad show only the link)
I need to embed the images into the file. ¿How can i do it?
I am a registered user of CAD Export VCL 9.1.5

Best Regards.

Re: Embed images into DXF file

Posted: 20 Feb 2014, 17:29
by support
Hello Jose,

You need to use TsgDXFOle2Frame entity for embedding a raster image into a DXF file. The code below generates TsgDXFOle2Frame entity from the bitmap stored in a file and inserts it at some point with X, Y coordinates.

Code: Select all

uses
  ..., sgOLE;

var
  Img: TsgCADImage;
...

procedure AddImageAsOLE(AFileName: string; AX, AY: TsgFloat);
var
  vBitmap: TBitmap;
  vOLE2Frame: TsgDXFOle2Frame;
begin
  vOLE2Frame := TsgDXFOle2Frame.Create;
  vBitmap := TBitmap.Create;
  try
    vBitmap.LoadFromFile(AFileName);
    vOLE2Frame.BinaryData := CreateSTGMFromImage(vBitmap, CF_BITMAP);
    vOLE2Frame.Point := MakeFPoint(AX, AY, 0);
    vOLE2Frame.Point1 := MakeFPoint(vOLE2Frame.Point.X + vBitmap.Width, vOLE2Frame.Point.Y + vBitmap.Height, 0);
  finally
    vBitmap.Free
  end;
  Img.CurrentLayout.AddEntity(vOLE2Frame);
  if Assigned(Img.Converter.OnCreate) then
    Img.Converter.OnCreate(vOLE2Frame);
  Img.Converter.Loads(vOLE2Frame);
end;
Mikhail.

Re: Embed images into DXF file

Posted: 23 Feb 2014, 11:05
by jose_olalla
Perfect!
Works like a charm.

Thanks so much.

Re: Embed images into DXF file

Posted: 04 Sep 2015, 17:00
by cadusermast_
Hello,
I tried your code snippet within my project loaded a *.stl file, does not work. Is it possible to embedd bmp within a *.stl file?

Re: Embed images into DXF file

Posted: 04 Sep 2015, 18:23
by support
Hello,

It is possible to embed a BMP image into an STL file as the Ole2Frame object. Make sure you reload a CAD image into Tsg3DDrawingNavigator after embedding a BMP image:

Code: Select all

FImg: TsgCADImage;
F3DN: Tsg3DDrawingNavigator;
...

AddImageAsOLE('c:\image.bmp', 0, 0);
F3DN.LoadFromConverter(FImg.Converter, FImg);
Mikhail