Page 1 of 1

How to export DXF to PNG?

Posted: 23 Jan 2020, 19:33
by uligerhardt
I have DXFs that I want to convert to PNG. What's the best option to achieve this?

Re: How to export DXF to PNG?

Posted: 27 Jan 2020, 13:25
by support
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

Re: How to export DXF to PNG?

Posted: 29 Jan 2020, 16:00
by uligerhardt
Thanks, Mikhail!

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

Best regards,
Uli

Re: How to export DXF to PNG?

Posted: 26 Mar 2020, 13:19
by Razgriz101
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!