CAD .NET是一款功能强大的CAD图形绘制、处理、导入和导出的.NET控件,支持多种CAD格式,可以通过代码或者可视化绘制CAD图形,并且可以导出绘制的CAD图形为多种其他文件格式,下面的代码讲述了如何将DWG文件格式转换为位图格式:
using CADImport;
using CADImport.DWG;
using CADImport.DXF;
using CADImport.RasterImage;
private void CAD_to_BMP_Click(object sender, EventArgs e)
{
if ((OpenFileDialog1.ShowDialog() != DialogResult.OK)) return;
//CADImage.CreateImageByExtension detects format by the extension specified in the argument.
//The correct class for any supported format will be used automatically. We recommend to
//create a new drawing object with CADImage.CreateImageByExtension if import from the existed
//file/stream is required.
CADImage vDrawing = CADImage.CreateImageByExtension(OpenFileDialog1.FileName);
vDrawing.LoadFromFile(OpenFileDialog1.FileName);
// The bitmap will have 1000 px width, height will be calulated automatically
Bitmap vBitmap = new Bitmap(1000, (int)(1000 * vDrawing.AbsHeight / vDrawing.AbsWidth));
Graphics vGr = Graphics.FromImage(vBitmap);
RectangleF vRect = new RectangleF(0, 0, (float)1000, (float)(vBitmap.Width * vDrawing.AbsHeight / vDrawing.AbsWidth));
vDrawing.Draw(vGr, vRect);
vBitmap.Save(OpenFileDialog1.FileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}