How to add Images(BMP/JPEG) in DXF

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

Moderators: SDS, support, admin

Post Reply
avimms
Posts: 13
Joined: 06 Dec 2005, 09:57
Location: India

How to add Images(BMP/JPEG) in DXF

Post by avimms » 09 Mar 2007, 13:38

Hi,

How can I add an image into DXFImage, using DXF Import VCL.

Thanks & Regards,
Avinash

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

Post by support » 09 Mar 2007, 14:14

Hello!

Please try the following code:

Code: Select all

<b>uses</b>
  ... SGImage, DXFImage, DXFConv, sgConsts;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    ...
    btnOpenCAD: TButton;
    btnAddBMP: TButton;
    sgImage1: TsgImage;
    <b>procedure</b> btnOpenCADClick(Sender: TObject);
    <b>procedure</b> btnAddBMPClick(Sender: TObject);
  <b>private</b>
    <font color="blue"><i>{ Private declarations }</i></font id="blue">
    FImg: TsgDXFImage;
  ...


<b>procedure</b> TForm1.btnOpenCADClick(Sender: TObject);
<b>begin</b>
  sgImage1.LoadFromFile(<font color="blue">'c:\Test.dxf'</font id="blue">);
  <b>if</b> sgImage1.Picture.Graphic <b>is</b> TsgDXFImage <b>then
  begin</b>
    FImg := TsgDXFImage(sgImage1.Picture.Graphic);
    sgImage1.Align := alClient;
  <b>end
  else</b>
    FImg := <b>nil</b>;
<b>end</b>;

<b>procedure</b> TForm1.btnAddBMPClick(Sender: TObject);
<b>var</b>
  Ent: TsgDXFEntity;

  <b>function</b> GetBitMap: TsgDXFEntity;
  <b>var</b>
    vBitMap: TBitmap;
    vImageEnt: TsgDXFImageEnt <b>absolute</b> Result;
  <b>begin</b>
    Result := <b>nil</b>;

    vBitMap := TBitmap.Create;
    <b>try</b>
      vBitMap.LoadFromFile(<font color="blue">'c:\Test.bmp'</font id="blue">);
    <b>except</b>
      vBitMap.Free;
      Exit;
    <b>end</b>;
    vImageEnt := TsgDXFImageEnt.Create;
    vImageEnt.Point := MakeFPoint(<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">);
    vImageEnt.Point1 := MakeFPoint(vBitMap.Width, <font color="blue">0</font id="blue">, <font color="blue">0</font id="blue">);
    vImageEnt.Point2 := MakeFPoint(<font color="blue">0</font id="blue">, vBitMap.Height, <font color="blue">0</font id="blue">);
    vImageEnt.Point3 := MakeFPoint(<font color="blue">0.5</font id="blue">,<font color="blue">0.5</font id="blue">,<font color="blue">0.5</font id="blue">);
    vImageEnt.SetImage(vBitMap);
    vBitMap.Free;
  <b>end</b>;

<b>begin
  if</b> FImg = <b>nil then</b>
    Exit;

  Ent := GetBitMap;
  <b>if</b> Ent <> <b>nil then
  begin</b>
    FImg.Converter.Sections[csEntities].AddEntity(Ent);
    <b>if</b> Assigned(FImg.Converter.OnCreate) <b>then</b>
      FImg.Converter.OnCreate(Ent);
    FImg.Converter.Loads(Ent);
    FImg.GetExtents;
    FImg.RefreshCurrentLayout;
    sgImage1.Width := FImg.Width;
    sgImage1.Height := FImg.Height;
    sgImage1.Align := alClient;
    sgImage1.Invalidate;
  <b>end</b>;
<b>end</b>;

<b>end</b>.
Sergey.

Please post questions to the forum or write to support@cadsofttools.com

avimms
Posts: 13
Joined: 06 Dec 2005, 09:57
Location: India

Post by avimms » 12 Mar 2007, 09:35

Hi Sergey,

Thanks for the answer. I was trying to add an image based on code snippet you have sent for some other query in the forum, which makes use of TsgDXFImageDef class to load the picture. However I could not see the image after adding it. I found out that my DXF map is having large dimension and image that I was adding is very small in dimension compared to the map. I need to scale the image to see it clearly.

What is the difference between TsgDXFImageDef and TsgDXFImageEnt class? When I am suppose to make use of each one? I would be grateful if you let me know, as I have no background of CAD.

Thanks & Regards,
Avinash

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

Post by support » 12 Mar 2007, 12:36

Hello Avinash!

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Thanks for the answer. I was trying to add an image based on code snippet you have sent for some other query in the forum, which makes use of TsgDXFImageDef class to load the picture. However I could not see the image after adding it. I found out that my DXF map is having large dimension and image that I was adding is very small in dimension compared to the map. I need to scale the image to see it clearly. <hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

We have respective example of using TsgDXFImageDef at the following topic: http://www.soft-gold.ru/forum/topic.asp?TOPIC_ID=202
To make added image bigger use the following lines:

Code: Select all

  vImageEnt.Point3 := MakeFPoint(<font color="blue">100</font id="blue">,<font color="blue">100</font id="blue">,<font color="blue">1</font id="blue">);
or

Code: Select all

  vImageEnt.Point1 := MakeFPoint(<font color="blue">2.5</font id="blue">, <font color="blue">0</font id="blue">, <font color="blue">0</font id="blue">);//width
  vImageEnt.Point2 := MakeFPoint(<font color="blue">0</font id="blue">, <font color="blue">2.5</font id="blue">, <font color="blue">0</font id="blue">);//heigth
  vImageEnt.Point3 := MakeFPoint(<font color="blue">100</font id="blue">,<font color="blue">100</font id="blue">,<font color="blue">1</font id="blue">);//scale
or

Code: Select all

  vImageEnt.Point1 := MakeFPoint(vImageDef.Picture.Width,<font color="blue">0</font id="blue">,<font color="blue">0</font id="blue">);//width
  vImageEnt.Point2 := MakeFPoint(<font color="blue">0</font id="blue">, vImageDef.Picture.Height,<font color="blue">0</font id="blue">);//heigth
  vImageEnt.Point3 := MakeFPoint(<font color="blue">1</font id="blue">,<font color="blue">1</font id="blue">,<font color="blue">1</font id="blue">);//scale
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">What is the difference between TsgDXFImageDef and TsgDXFImageEnt class? When I am suppose to make use of each one? I would be grateful if you let me know, as I have no background of CAD. <hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
TsgDXFImageDef serves as the container for TsgDXFImageEnt. Actually TsgDXFImageEnt contains a reference to the image in the TsgDXFImageDef. For instance, this is useful when you have one large raster image which has to be displayed in several places in your CAD file. In this case TsgDXFImageDef is used for storing raster image and TsgDXFImageEnt is used for its further allocation.
If you have some different raster images we recommend to use TsgDXFImageEnt directly.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

avimms
Posts: 13
Joined: 06 Dec 2005, 09:57
Location: India

Post by avimms » 12 Mar 2007, 16:41

Sergey,

Thanks for clarification. So I need to "FindPicture" of interest, using TsgDXFImageDef.Handle property and get it in TsgDXFImageEnt object and add it in DXF image. It means, duplication of "image data" is avoided, right? Or does it just avoids creation of TBitmap and assigning it to TsgDXFImageEnt?

Regards,
Avinash

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

Post by support » 12 Mar 2007, 17:28

Avinash, hello oce again.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">It means, duplication of "image data" is avoided, right?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Yes, it is. Duplication of "image data" is avoided when using construction TsgDXFImageDef - TsgDXFImageEnt.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Or does it just avoids creation of TBitmap and assigning it to TsgDXFImageEnt? <hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
It is also avoids creation of TBitmap and further assigning it to TsgDXFImageEnt.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Post Reply