TIFF image flipped when converted

1 2    next >
Ahmad Soliman
1/14/2018 10:06 AM

Dear Sir
I'm trying to convert the attached DWG file to TIFF, using this code

C# Code:
string fileName = lstFiles.SelectedItem.Value.ToString();
            string MyDir = txtPath.Text + @"\";
            string filename = MyDir + fileName;
            DxfModel model = DwgReader.Read(filename);


            System.Drawing.Size maxSize = new System.Drawing.Size(7000, 7000);
            foreach (DxfLayout layout in model.Layouts)
            {
                
                Bitmap image = ImageExporter.CreatePlotLayoutBitmap(maxSize,
                                                                    model, layout, null,
                                                                    GraphicsConfig.WhiteBackgroundCorrectForBackColor,
                                                                System.Drawing.Drawing2D.SmoothingMode.HighQuality);

                if (image != null)
                {
                    using (
                        FileStream output =
                            new FileStream(MyDir + layout.Name + ".tiff",
                                FileMode.Create))
                    {
                        ImageExporter.EncodeImageToTiff(image, output);
                    }
                }
            }

But the image is flipped
I'm attaching the conversion result and the dwg file
thanks

Ahmad Soliman
1/14/2018 10:18 AM

I used

C# Code:
image.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

and the image is showed good now, but the lower right piece of the cad file didn't appear on the converted tiff file
i'm attaching the converted file and the viewon Autocad

Ahmad Soliman
1/14/2018 10:37 AM

UPDATE
Sorry, my bad, I'm not a pro in Autocad, but it seems that the Autocad file references some layers from an external file (T-BLOCK.dwg).
Is there a method can i merge both files together before or during the conversion ?
Attached T-BLOCK.dwg

Ahmad Soliman
1/14/2018 11:09 AM

Update 2:
I found the solution
to loop on the template entities and add it to the desired layout

C# Code:
foreach (DxfEntity entity in blockModel.Entities)
                {
                    layout.Entities.Add(entity);
                }

Wout
1/14/2018 11:18 AM

If a drawing references another drawing through DxfBlock.ExternalReference, the correct way to load them is to call DxfModel.LoadExternalReferences().

Adding objects from drawing A to drawing B is incorrect. The only way to do that is to clone the objects first, see the documentation in DxfHandledObject.Clone() and follow the example closely.

- Wout

Wout
1/15/2018 12:03 PM

Hi,

There was indeed a bug in the y-axis reversal for this specific ImageExporter method. Please download the latest CadLib 4.0 version for a patch. Also I've modified your program a little to load the external references and to properly export model space:

C# Code:
            DxfModel model = CadReader.Read(fileName, true /* This will load unknown objects with proxy graphics */);
            model.LoadExternalReferences();

            System.Drawing.Size maxSize = new System.Drawing.Size(7000, 7000);
            foreach (DxfLayout layout in model.Layouts) {
                if (!layout.PaperSpace) {
                    // Model space plot window area is usually not initialized as it is expected that the user
                    // selects a rectangle in the AutoCAD user interface.
                    if (layout.PlotArea == PlotArea.SpecifiedByPlotWindowArea) {
                        BoundsCalculator boundsCalculator = new BoundsCalculator();
                        boundsCalculator.GetBounds(model);
                        layout.PlotWindowArea = new Rectangle2D(
                            (Point2D)boundsCalculator.Bounds.Min,
                            (Point2D)boundsCalculator.Bounds.Max);
                    }
                }
                Bitmap image = 
                    ImageExporter.CreatePlotLayoutBitmap(
                        maxSize,
                        model, 
                        layout, 
                        null,
                        GraphicsConfig.WhiteBackgroundCorrectForBackColor,
                        System.Drawing.Drawing2D.SmoothingMode.HighQuality);

                if (image != null) {
                    using (
                        FileStream output =
                            new FileStream(fileName + " - " + layout.Name + ".tiff",
                                FileMode.Create)) {
                        ImageExporter.EncodeImageToTiff(image, output);
                    }
                }
            }

Thank you for the report!

- Wout

Wout
1/15/2018 1:24 PM

By the way, for model space method ImageExporter.CreatePlotLayoutBitmap is perhaps not the most reliable option. I don't think users normally enter the plotting information for model space. So therefore method ImageExporter.CreateAutoSizedBitmap(DxfModel model, Matrix4D transform, GraphicsConfig graphicsConfig, SmoothingMode smoothingMode, Size maxSize) is in general more useful.

You can check property DxfLayout.Paperspace to see whether it is a model space or paper space layout.

- Wout

Ahmad Soliman
1/16/2018 7:16 AM

Thank you,
I'll update it

Ahmad Soliman
1/17/2018 6:01 AM

Dear Sir,
Thank you, the update is working great.
But Some files when converted showing a red triangles. i attached sample of them with the DWG files



Wout
1/17/2018 7:50 AM

That's pretty avant garde looking ;), I'll check out what's going on today!

- Wout

1 2    next >