乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: bikelink

不使用autocad如何得到预览dwg?

[复制链接]

3

主题

28

帖子

1

银币

初来乍到

Rank: 1

铜币
40
发表于 2010-11-15 12:47:13 | 显示全部楼层

你是说,它在AutoCAD 64位创建的DWG文件上运行良好?好吧,我们当然希望有这种兼容性…
不过需要注意的是:这些结构并不像它们在图形中那样被打包,因为在Keith的代码中,每个字段都与本机单词边界对齐。我尝试了一个到F#的快速脏端口(我情不自禁),并试图通过固定BinaryReader.ReadBytes返回的字节[]来直接读取结构。这可能不是最有效的方法,并且可能会带来一些具有终结性的问题。顺便说一句,图像格式看起来像是PNG。代码如下:
  1. #nowarn "9"
  2. //Copyright 2009 K.E. Blackie
  3. //This work is based in part from a VBA macro
  4. //initially developed by members of www.vbdesign.net
  5. //it may be used freely and may be modified to suit
  6. //your needs as long as credit is given where it is due
  7. open System.IO
  8. open System.Runtime.InteropServices
  9. []
  10. type BITMAPINFOHEADER =
  11.     val biSize: int32
  12.     val biWidth: int32
  13.     val biHeight: int32
  14.     val biPlanes: int16
  15.     val biBitCount: int16
  16.     val biCompression: int32
  17.     val biSizeImage: int32
  18.     val biXPelsperMeter: int32
  19.     val biYPelsPerMeter: int32
  20.     val biClrUsed: int32
  21.     val biClrImportant: int32
  22. []
  23. type IMGREC =
  24.     val bytType: byte
  25.     val lngStart: int32
  26.     val lngLen: int32
  27. []
  28. type RGBQUAD =
  29.     val rgbBlue: byte
  30.     val rgbGreen: byte
  31.     val rgbRed: byte
  32.     val rgbReserved: byte
  33. let byteToType(reader: BinaryReader) =
  34.     let bytes = reader.ReadBytes(Marshal.SizeOf(typeof))
  35.     let handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
  36.     let theStructure = Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof) :?> 'T
  37.     handle.Free()
  38.     theStructure
  39. let getThumbnail strFile boolRetainBackColor boolSaveToFile strSaveName =
  40.    
  41.     let mutable bmp =
  42.         new System.Drawing.Bitmap(
  43.             1, 1, System.Drawing.Imaging.PixelFormat.Format8bppIndexed )
  44.     if File.Exists strFile then
  45.         let fs = File.OpenRead strFile
  46.         try
  47.             use br = new BinaryReader(fs)
  48.             fs.Seek(13L, SeekOrigin.Begin) |> ignore
  49.             let lngImgLoc = br.ReadInt32()
  50.             fs.Seek(int64 lngImgLoc + 17L, SeekOrigin.Begin) |> ignore
  51.             let lngCurLoc = lngImgLoc + 17
  52.             fs.Seek(int64 lngCurLoc + 3L, SeekOrigin.Begin) |> ignore
  53.             let bytCnt = br.ReadByte()
  54.             if bytCnt > 1uy then
  55.                 let intCnt = ref 0
  56.                 while !intCnt  ignore
  57.                         let udtHeader = byteToType[B] br
  58.                         if udtHeader.biBitCount = 8s then
  59.                             let udtColors =
  60.                                 [|  for count = 0 to 255 do
  61.                                         yield byteToType br |]
  62.                             fs.Seek(int64 udtRec.lngStart, SeekOrigin.Begin) |> ignore
  63.                             let bytBMPBuff = br.ReadBytes udtRec.lngLen
  64.                             bmp  System.Drawing.ColorTranslator.ToOle
  65.                                     let lngColor =
  66.                                         if boolRetainBackColor then lngColor
  67.                                         elif lngColor = System.Drawing.ColorTranslator.ToOle System.Drawing.Color.Black then
  68.                                             System.Drawing.ColorTranslator.ToOle System.Drawing.Color.White
  69.                                         elif lngColor = System.Drawing.ColorTranslator.ToOle System.Drawing.Color.White then
  70.                                             System.Drawing.ColorTranslator.ToOle System.Drawing.Color.Black
  71.                                         else lngColor
  72.                                     bmp.SetPixel(udtHeader.biWidth - x,  y, System.Drawing.ColorTranslator.FromOle lngColor)
  73.                                     decr lngCnt
  74.                             intCnt := int bytCnt
  75.         finally
  76.             fs.Close()
  77.    
  78.     if boolSaveToFile then
  79.         if System.String.IsNullOrEmpty strSaveName then
  80.             let fName =
  81.                 System.String.Concat(
  82.                     Path.GetTempPath(),
  83.                     Path.GetFileNameWithoutExtension(Path.GetRandomFileName()),
  84.                     ".bmp" )
  85.             bmp.Save fName
  86.         else
  87.             bmp.Save strSaveName
  88.     bmp

回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2010-11-15 13:09:38 | 显示全部楼层
嗯......我提供的代码只是为了提取位图预览并让用户看到它,没有别的,其他人可以使用它。还是不是..这真的没什么区别。
回复

使用道具 举报

3

主题

28

帖子

1

银币

初来乍到

Rank: 1

铜币
40
发表于 2010-11-16 03:10:43 | 显示全部楼层

嗨,Keith,
不要误会我的意思。您的代码很棒,是提取预览图像的有用示例。如果你没有发布它,这真的会有所不同(甚至更糟)。可能是我自己缺乏经验,我被现场包装问题搞糊涂了,因为这有点出乎我的意料。
非常感谢您的信息和启发!真诚的,托尔斯滕
回复

使用道具 举报

7

主题

46

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
74
发表于 2011-6-14 15:27:42 | 显示全部楼层
谢谢基思。
比我升级前使用的简单多了。
回复

使用道具 举报

154

主题

1274

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1936
发表于 2011-6-15 11:36:52 | 显示全部楼层
不用谢
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 16:44 , Processed in 0.763251 second(s), 61 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表