DWG to PNG conversion result is corrupted

Apose CAD for .NET version 22.6.0 running on .NET 3.1

This is the snippet that i’m running

var rasterizationOptions = new CadRasterizationOptions()
                    {
                        PageWidth = 2160,
                        PageHeight = 2160,
                        DrawColor = Color.DarkBlue
                    };

                    var options = new PngOptions();
                    options.VectorRasterizationOptions = rasterizationOptions;
                    image.Save(destinationDirectory, options);

I’m trying to convert DWG to PNG but the file get corrupted, i attached the result that i’m getting.
teste.png (33.4 KB)

here is the DWG file
testDwg.zip (150.1 KB)

@FireBlaster223,
please, attach also your dwg file so we can debug it.

testDwg.zip (150.1 KB)

@FireBlaster223,
unfortunately, the header of this file contains incorrect size of the drawing (EXTMIN, EXTMAX variables). You can run cadImage.UpdateSize(); after loading to recover size of the drawing and export after it.

Ok, I understand the problem but don’t get the solution, i’m new at this lib, i must import cadImage or it’s a method that already exist?

@FireBlaster223,
this is the entire example for your file:

string fileName = "testDWG.dwg";
string outPath = fileName + ".png";

using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
    cadImage.UpdateSize();

    var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
    {
        PageWidth = 2160,
        PageHeight = 2160,
        DrawColor = Color.DarkBlue
    };
    PngOptions pngOptions = new PngOptions
    {
        VectorRasterizationOptions = rasterizationOptions
    };
    cadImage.Save(outPath, pngOptions);
}
1 Like

It worked ! thanks a lot for the help, didn’t find this problem anywhere.

1 Like

@FireBlaster223,
welcome, was happy to help.