autocad型源代码_C# 实现预览dwg文件完整源代码(无需autocad环境)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace WindowsApplication3
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(16, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(416, 272);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 310);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pictureBox1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
ViewDWG viewDWG=new ViewDWG();
pictureBox1.Image =viewDWG.GetDwgImage("c:\\\\1.dwg");
}
}
class ViewDWG
{
struct BITMAPFILEHEADER
{
public short bfType;
public int bfSize;
public short bfReserved1;
public short bfReserved2;
public int bfOffBits;
}
public Image GetDwgImage(string FileName)
{
if (!(File.Exists(FileName)))
{
throw new FileNotFoundException("文件没有被找到");
}
FileStream DwgF; //文件流
int PosSentinel; //文件描述块的位置
BinaryReader br; //读取二进制文件
int TypePreview; //缩略图格式
int PosBMP; //缩略图位置
int LenBMP; //缩略图大小
short biBitCount; //缩略图比特深度
BITMAPFILEHEADER biH; //BMP文件头,DWG文件中不包含位图文件头,要自行加上去
byte[] BMPInfo; //包含在DWG文件中的BMP文件体
MemoryStream BMPF = new MemoryStream(); //保存位图的内存文件流
BinaryWriter bmpr = new BinaryWriter(BMPF); //写二进制文件类
Image myImg = null;
try
{
DwgF = new FileStream(FileName, FileMode.Open, FileAccess.Read); //文件流
br = new BinaryReader(DwgF);
DwgF.Seek(13, SeekOrigin.Begin); //从第十三字节开始读取
PosSentinel = br.ReadInt32(); //第13到17字节指示缩略图描述块的位置
DwgF.Seek(PosSentinel + 30, SeekOrigin.Begin); //将指针移到缩略图描述块的第31字节
TypePreview = br.ReadByte(); //第31字节为缩略图格式信息,2 为BMP格式,3为WMF格式
if (TypePreview == 1)
{
}
else if (TypePreview == 2 || TypePreview == 3)
{
PosBMP = br.ReadInt32(); //DWG文件保存的位图所在位置
LenBMP = br.ReadInt32(); //位图的大小
DwgF.Seek(PosBMP + 14, SeekOrigin.Begin); //移动指针到位图块
biBitCount = br.ReadInt16(); //读取比特深度
DwgF.Seek(PosBMP, SeekOrigin.Begin); //从位图块开始处读取全部位图内容备用
BMPInfo = br.ReadBytes(LenBMP); //不包含文件头的位图信息
br.Close();
DwgF.Close();
biH.bfType = 19778; //建立位图文件头
if (biBitCount
{
biH.bfSize = 54 + 4 * (int)(Math.Pow(2, biBitCount)) + LenBMP;
}
else
{
biH.bfSize = 54 + LenBMP;
}
biH.bfReserved1 = 0; //保留字节
biH.bfReserved2 = 0; //保留字节
biH.bfOffBits = 14 + 40 + 1024; //图像数据偏移
//以下开始写入位图文件头
bmpr.Write(biH.bfType); //文件类型
bmpr.Write(biH.bfSize); //文件大小
bmpr.Write(biH.bfReserved1); //0
bmpr.Write(biH.bfReserved2); //0
bmpr.Write(biH.bfOffBits); //图像数据偏移
bmpr.Write(BMPInfo); //写入位图
BMPF.Seek(0, SeekOrigin.Begin); //指针移到文件开始处
myImg = Image.FromStream(BMPF); //创建位图文件对象
bmpr.Close();
BMPF.Close();
}
return myImg;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
autocad型源代码_C# 实现预览dwg文件完整源代码(无需autocad环境)相关推荐
- winform界面嵌入dwg图纸_C# 实现预览dwg文件完整源代码(无需autocad环境)
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using Sys ...
- C# 实现预览dwg文件完整源代码(无需autocad环境)
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using Sys ...
- winform界面嵌入dwg图纸_WPF中使用WinForm控件预览DWG文件(学习笔记)
操作环境:XP,C# ,.Net4.0和VS2010中测试 WinForm中使用DWGThumbnail不用这么麻烦,下面讨论的是在WPF中使用,WPF中无法直接引用DWGThumbnail.ocx来 ...
- html预览dwg文件,大佬救命!有关dwg文件预览的问题
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 请问有人做过dwg的文件预览吗,网上的代码有版本限制,用最新版的AutoCAD保存的dwg文件会提示参数无效,有大佬做过这个吗? 异常信息: 未处理Sys ...
- html预览dwg文件,如何使用纯javascript autodesk在查看器中脱机显示二维(.dwg)文件
请确保已完全下载所有提取的DWG可见气泡,并且要加载的模型路径正确,因为错误代码5代表 NETWORK_FILE_NOT_FOUND . var options = { env: 'Local', } ...
- 想实现高德/百度示例中 源代码编辑器+效果预览
刚学习前端不久,想实现如下 源代码编辑器+效果预览 的效果,没有什么思路,希望有人能指导一下
- winform界面嵌入dwg图纸_完美解决窗体中预览DWG图形(C#版)
看到完美解决VB.NET窗体中预览DWG图形帖子后,用C#代码 实现如下: class ViewDWG { struct BITMAPFILEHEADER { public short bfType; ...
- CAD(dxf、dwg格式)文件的读取和显示,真正实现通过代码预览CAD文件,包含解析dwg、dxf文件,可以提取标注信息,可以转换为pdf、png、tiff、gif等6种格式的文件,可以永久免费实用
真正实现通过代码预览CAD文件,包含解析dwg.dxf文件,可以提取标注信息,可以转换为pdf.png.tiff.gif等6种格式的文件,可以永久免费实用. 网上看了很多资料,不是缺这个就是少那个,反 ...
- html如何找寻vue文件,如何预览vue文件
每天写个页面,都要配置脚手架,能不能像以前开发前端页面一样,写一个index.html,然后编写js,css,就可以在浏览器上运行了呢?可是我又不想舍弃vue,那么能不能全局搭建一个脚手架,供我来使用 ...
最新文章
- 开源大咖齐聚2020启智开发者大会,共探深度学习技术未来趋势
- eeglab中文教程系列(16)-Time/Frequency decomposition
- FatFs文件系统的移植
- RabbitMQ路由模式
- JUNOS Olive GRE Tunnel Configuration
- 【Breadth-first Search 】515. Find Largest Value in Each Tree Row
- 如何在Eclipse中添加Servlet-api.jar的方法
- UE4 性能优化方法(工具篇)
- dcmtk编译 android,windows下编译dcmtk的Android版本
- GsonFormat的使用
- python字符串变量替换_Python基于template实现字符串替换
- Bailian2967 特殊日历计算【日期计算】
- 中国石油大学(北京)-《 公共社交礼仪 》-​​​​​​​第一阶段在线作业
- 由于找不到MSVCR100.dll,无法继续执行代码解决方法
- 计算机系统存储器 分类,存储器的分类
- 阿里巴巴最新分销模式淘易客分销
- linux中硬链接为什么不能跨分区
- Android7.1 亮度自动调节
- win10未能解析服务器名,win10系统提示“无法解析服务器的dns地址”的修复方法...
- 做独立站要做私域营销,做亚马逊更要做私域营销,Why?