Hi majidp.star,
First install the netDxf.netstandard from nugetr using the below command.
Install-Package netDxf.netstandard -Version 2.4.0
Then use the below code to convert image to dxf file.
Namespaces
C#
using netDxf;
using netDxf.Objects;
using netDxf.Units;
VB.Net
Imports netDxf
Imports netDxf.Objects
Imports netDxf.Units
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
ImageDefinition imageDef = new ImageDefinition(Server.MapPath("~/Jellyfish.jpg"));
imageDef.ResolutionUnits = ImageResolutionUnits.Centimeters;
double width = imageDef.Width / imageDef.HorizontalResolution;
double height = imageDef.Height / imageDef.VerticalResolution;
netDxf.Entities.Image image = new netDxf.Entities.Image(imageDef, new Vector2(0, 0), width, height);
image.Rotation = 30;
double x = width / 4;
double y = height / 4;
ClippingBoundary clip = new ClippingBoundary(x, y, 2 * x, 2 * y);
image.ClippingBoundary = clip;
DxfDocument doc = new DxfDocument();
doc.AddEntity(image);
doc.Save(Server.MapPath("~/Jellyfish.dxf"));
DxfDocument test = DxfDocument.Load(Server.MapPath("~/Jellyfish.dxf"));
test.Save(Server.MapPath("~/Jellyfish1.dxf"));
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim imageDef As ImageDefinition = New ImageDefinition(Server.MapPath("~/Jellyfish.jpg"))
imageDef.ResolutionUnits = ImageResolutionUnits.Centimeters
Dim width As Double = imageDef.Width / imageDef.HorizontalResolution
Dim height As Double = imageDef.Height / imageDef.VerticalResolution
Dim image As netDxf.Entities.Image = New netDxf.Entities.Image(imageDef, New Vector2(0, 0), width, height)
image.Rotation = 30
Dim x As Double = width / 4
Dim y As Double = height / 4
Dim clip As ClippingBoundary = New ClippingBoundary(x, y, 2 * x, 2 * y)
image.ClippingBoundary = clip
Dim doc As DxfDocument = New DxfDocument()
doc.AddEntity(image)
doc.Save(Server.MapPath("~/Jellyfish.dxf"))
Dim test As DxfDocument = DxfDocument.Load(Server.MapPath("~/Jellyfish.dxf"))
test.Save(Server.MapPath("~/Jellyfish1.dxf"))
End Sub
Reference:
https://csharp.hotexamples.com/examples/netDxf.Entities/Image/-/php-image-class-examples.html