Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example on how to use DxfImage #157

Open
ponahoum opened this issue Apr 7, 2021 · 4 comments
Open

Example on how to use DxfImage #157

ponahoum opened this issue Apr 7, 2021 · 4 comments

Comments

@ponahoum
Copy link

ponahoum commented Apr 7, 2021

Hi,

I am trying to use the DxfImage entity to insert an image dependency into my DXF but I cannot make it work. The DXF output seems not to contain the image attributes that I put. Does anyone have a working example?

DxfImage image = new DxfImage(imagePath: "test.png", new DxfPoint(0,0,0), 256,256, new DxfVector(256,256,1));
dxfFile.Entities.Add(image);

Thanks !

@ponahoum
Copy link
Author

ponahoum commented Apr 7, 2021

Ok I actually found out reading the tests that to make it work you need to add file.Header.Version = DxfAcadVersion.R14 :

var file = new DxfFile();
file.Header.Version = DxfAcadVersion.R14; // DxfImage is only supported on >= R14

@ponahoum ponahoum closed this as completed Apr 7, 2021
@ponahoum ponahoum reopened this Apr 7, 2021
@ponahoum
Copy link
Author

ponahoum commented Apr 7, 2021

Although the attributes are now in the DXF, i can't manage to make autocad open the DXF with the image as an external reference. The dependency doesn't seem to be considered even though it is included in the DXF file. Any idea on how to achieve this ? Here's my generation code:

            //Setup the file
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R14; // DxfImage is only supported on >= R14

            //Adding a line to test
            DxfLine aLine = new DxfLine();
            aLine.P1 = new DxfPoint(0, 0, 0);
            aLine.P2 = new DxfPoint(0, 1, 0);
            file.Entities.Add(aLine);

            //Setting up the image
            var image = new DxfImage("TestImage.png", DxfPoint.Origin, 1920, 1080, new DxfVector(19.2, 10.8, 0.0));
            image.IsVisible = true;
            image.ShowImage = true;
            file.Entities.Add(image);

            //Write the file
            using (FileStream filestream = new FileStream(outputPath, FileMode.Create))
            file.Save(filestream);

@brettfo
Copy link
Member

brettfo commented Apr 7, 2021

IMAGE entities are problematic because AutoCAD is really picky about what the file looks like, and I haven't yet been able to determine exactly what that is. Using your example code an image displays correctly both in the ODA Viewer app as well as LibreCAD, but not AutoCAD 2016 (I don't have any other programs to test with.) I even did a Save As from LibreCAD and AutoCAD still couldn't open it; it seems that IMAGE is a problem for everybody.

@ponahoum
Copy link
Author

ponahoum commented Apr 8, 2021

I tried with AutoCAD 2020 and it ignores the reference as well. Although I tried with AutoCAD 2020 and netDxf / ezDxf and it works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants