My current practice is as follows, but some of the maps are wrong.
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
#region
Aspose.CAD.FileFormats.Cad.CadTables.CadViewTableObject ss = new Aspose.CAD.FileFormats.Cad.CadTables.CadViewTableObject();
double Xmin = 0;
double Xmax = 0;
double Ymin = 0;
double Ymax = 0;
foreach (CadBaseEntity entity in cadImage.Entities)
{
if (entity is Aspose.CAD.FileFormats.Cad.CadObjects.Polylines.CadPolyline3D)
{
foreach (Cad3DVertex ttt in entity.ChildObjects)
{
if (ttt.LocationPoint.X < Xmin || Xmin == 0)
{
Xmin = ttt.LocationPoint.X;
}
if (ttt.LocationPoint.X > Xmax || Xmax == 0)
{
Xmax = ttt.LocationPoint.X;
}
if (ttt.LocationPoint.Y < Ymin || Ymin == 0)
{
Ymin = ttt.LocationPoint.Y;
}
if (ttt.LocationPoint.Y > Ymax || Ymax == 0)
{
Ymax = ttt.LocationPoint.Y;
}
}
}
}
double Dx = Xmax - Xmin;//
double Dy = Ymax - Ymin;
#endregion
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
double ImageWidth = cadImage.Width;//
double ImageHeight = cadImage.Height;
double ZommW = ImageWidth / Dx;//
double ZommH = ImageHeight / Dy;
double Zoom;
double PngW = width / ImageWidth;//
double PngH = height / ImageHeight;
if (ZommW > ZommH)
{
rasterizationOptions.Zoom = 1f * (float)ZommH;
Zoom = ZommH;
}
else
{
rasterizationOptions.Zoom = 1f * (float)ZommW;
Zoom = ZommW;
}
if (PngW > PngH)
{
rasterizationOptions.PageWidth = (float)ImageWidth * (float)PngH;
rasterizationOptions.PageHeight = (float)ImageHeight * (float)PngH;
}
else
{
rasterizationOptions.PageWidth = (float)ImageWidth * (float)PngW;
rasterizationOptions.PageHeight = (float)ImageHeight * (float)PngW;
}
ImageOptionsBase options = new Aspose.CAD.ImageOptions.PngOptions();
options.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + FileName + ".png";
cadImage.Save(MyDir, options);