How to export DXF to PNG?

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

Moderators: SDS, support, admin

Post Reply
uligerhardt
Posts: 8
Joined: 20 Jan 2015, 12:46

How to export DXF to PNG?

Post by uligerhardt » 23 Jan 2020, 19:33

I have DXFs that I want to convert to PNG. What's the best option to achieve this?

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

Re: How to export DXF to PNG?

Post by support » 27 Jan 2020, 13:25

Hello,

You should use the following approach:
  • Create a new TBitmap instance and draw CAD image graphics on the TBitmap.Canvas.

    Code: Select all

    function DrawToBitmap(AGraphic: TGraphic): TBitmap;
    begin
      Result := TBitmap.Create;
      Result.Width := AGraphic.Width;
      Result.Height := AGraphic.Height;
      Result.Canvas.StretchDraw(Rect(0, 0, AGraphic.Width, AGraphic.Height), AGraphic);
    end;
    
  • Create a new TPNGImage instance and copy the contents of the created TBitmap using a TPNGImage.Assign method.

    Code: Select all

    var
      vBitmap: TBitmap;
      vPNGImage: TPNGImage;
    ...
    
      vBitmap := DrawToBitmap(CADImage);
      vPNGImage := TPNGImage.Create;
      vPNGImage.Assign(vBitmap);
    
  • Save the PNG graphics to a file.

    Code: Select all

    var
      sFileName: string;
    ...
    
    vPNGImage.SaveToFile(sFileName);
    
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

uligerhardt
Posts: 8
Joined: 20 Jan 2015, 12:46

Re: How to export DXF to PNG?

Post by uligerhardt » 29 Jan 2020, 16:00

Thanks, Mikhail!

This works fine. I just had to make the PNG bigger than the DXF to avoid staircase effects.

Best regards,
Uli

Razgriz101
Posts: 2
Joined: 23 Mar 2020, 21:43

Re: How to export DXF to PNG?

Post by Razgriz101 » 26 Mar 2020, 13:19

THanks for the explanations! I did find about how to save the file as a .png myself, but couldn't find how to deal with the staircase effect. It's all good now, thanks again!

Post Reply