<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Thumbnail.OCX  for .NET 64 bit in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816923#M45406</link>
    <description>That's what I concluded. I'm using VS2008, does not support .NET 4.0.&lt;BR /&gt;Time for an upgrade.&lt;BR /&gt;Thanks for all your help.</description>
    <pubDate>Fri, 14 Feb 2014 20:01:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-02-14T20:01:56Z</dc:date>
    <item>
      <title>Thumbnail.OCX  for .NET 64 bit</title>
      <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816193#M45401</link>
      <description>&lt;P&gt;Back in the day I used the Thumbnail.ocx to display a preview of a dwg file in a form.&lt;/P&gt;&lt;P&gt;I need to upgrade (re-write)&amp;nbsp;an old VB6 program to the 21st centry using VB.NET and was wondering if there is a new version or a subsitute that I could use, maybe something from TrueView?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ray C.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2014 14:31:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816193#M45401</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-02-14T14:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Thumbnail.OCX  for .NET 64 bit</title>
      <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816507#M45402</link>
      <description>&lt;P&gt;You can find .NET code that retrieves thumbnail bitmap image from *.dwg file here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.theswamp.org/index.php?topic=30985.msg470910#msg470910" target="_blank"&gt;http://www.theswamp.org/index.php?topic=30985.msg470910#msg470910&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.theswamp.org/index.php?topic=45598.msg507524#msg507524" target="_blank"&gt;http://www.theswamp.org/index.php?topic=45598.msg507524#msg507524&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2014 16:45:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816507#M45402</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2014-02-14T16:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Thumbnail.OCX  for .NET 64 bit</title>
      <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816791#M45403</link>
      <description>Looks great.&lt;BR /&gt;This is a bit over my head but when I create my class it is throwing an error on the line&lt;BR /&gt;fs.CopyTo(ms, imageHeaderStart)&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Feb 2014 19:09:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816791#M45403</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-02-14T19:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Thumbnail.OCX  for .NET 64 bit</title>
      <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816793#M45404</link>
      <description>Sorry about that hit the worng key and submitted the post to quick.&lt;BR /&gt;&lt;BR /&gt;As I was syaing it is posting an development error that&lt;BR /&gt;'CopyTo' is not a member of 'System.IO.FileStream'&lt;BR /&gt;Have you had a chance to use that code?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks for the help&lt;BR /&gt;&lt;BR /&gt;Ray C.</description>
      <pubDate>Fri, 14 Feb 2014 19:12:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816793#M45404</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-02-14T19:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Thumbnail.OCX  for .NET 64 bit</title>
      <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816911#M45405</link>
      <description>&lt;P&gt;FileStream.CopyTo() method is only available since .NET4.0. Since all my Acad development targets Acad2012 or later, I stoped using .NET2/3.x.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I used the code with minor change, worked OK with AutoCAD 2012's drawing. Here is the static class I use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using System;
using System.Drawing;
using System.IO;

namespace DrawingThumbnail
{
    /// &amp;lt;summary&amp;gt;
    /// This code is originally from &lt;A href="http://www.theswamp.org:" target="_blank"&gt;http://www.theswamp.org:&lt;/A&gt;
    /// &lt;A href="http://www.theswamp.org/index.php?topic=30985.msg470910#msg470910" target="_blank"&gt;http://www.theswamp.org/index.php?topic=30985.msg470910#msg470910&lt;/A&gt;
    /// &lt;A href="http://www.theswamp.org/index.php?topic=45598.msg507524#msg507524" target="_blank"&gt;http://www.theswamp.org/index.php?topic=45598.msg507524#msg507524&lt;/A&gt;
    /// Minor code change has be made
    /// &amp;lt;/summary&amp;gt;
    public static class DwgThumbnail
    {
        public static Image GetBitmapFromDwgFile(string dwgFile)
        {
            if (!File.Exists(dwgFile))
            {
                throw new FileNotFoundException("Cannot find file: \"" + dwgFile + "\"");
            }

            if (!Path.GetExtension(dwgFile).ToUpper().EndsWith("DWG"))
            {
                throw new ArgumentException("Wrong file type: not a *.DWG file.");
            }

            Image img = null;

            using (FileStream fs = new FileStream(dwgFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    fs.Seek(0xd, SeekOrigin.Begin);
                    fs.Seek(0x14 + br.ReadInt32(), SeekOrigin.Begin);
                    byte bytCnt = br.ReadByte();
                    if (bytCnt &amp;lt;= 1)
                    {
                        return null;
                    }

                    int imageHeaderStart = 0;
                    int imageHeaderSize = 0;
                    byte imageCode = 0;
                    for (short i = 1; i &amp;lt;= bytCnt; i++)
                    {
                        imageCode = br.ReadByte();
                        imageHeaderStart = br.ReadInt32();
                        imageHeaderSize = br.ReadInt32();
                        
                        if (imageCode == 2)
                        {
                            //-----------------------------------------
                            // BMP Preview (2012 file format)
                            //-----------------------------------------

                            // BITMAPINFOHEADER (40 bytes)
                            br.ReadBytes(0xe);

                            //biSize, biWidth, biHeight, biPlanes
                            ushort biBitCount = br.ReadUInt16();
                            br.ReadBytes(4);

                            //biCompression
                            uint biSizeImage = br.ReadUInt32();

                            //br.ReadBytes(0x10); //biXPelsPerMeter, biYPelsPerMeter, biClrUsed, biClrImportant
                            fs.Seek(imageHeaderStart, SeekOrigin.Begin);
                            byte[] bitmapBuffer = br.ReadBytes(imageHeaderSize);
                            uint colorTableSize = 
                                Convert.ToUInt32(Math.Truncate((biBitCount &amp;lt; 9) ? 4 * Math.Pow(2, biBitCount) : 0));
                            using (MemoryStream ms = new MemoryStream())
                            {
                                using (BinaryWriter bw = new BinaryWriter(ms))
                                {
                                    bw.Write(Convert.ToUInt16(0x4d42));
                                    bw.Write(54u + colorTableSize + biSizeImage);
                                    bw.Write(new ushort());
                                    bw.Write(new ushort());
                                    bw.Write(54u + colorTableSize);
                                    bw.Write(bitmapBuffer);
                                    img = new Bitmap(ms);
                                }
                            }
                            
                        }       
                        else if (imageCode == 6)
                        {
                            //-------------------------------------------
                            // PNG Preview (2013 file format)
                            //-------------------------------------------
                            fs.Seek(imageHeaderStart, SeekOrigin.Begin);
                            using (MemoryStream ms = new MemoryStream())
                            {
                                fs.CopyTo(ms, imageHeaderStart);
                                img = Image.FromStream(ms);
                            }
                        }
                        else if (imageCode == 3)
                        {
                            //return null;
                        }
                    }
                }
            }

            return img;
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;HTH&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2014 19:58:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816911#M45405</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2014-02-14T19:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Thumbnail.OCX  for .NET 64 bit</title>
      <link>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816923#M45406</link>
      <description>That's what I concluded. I'm using VS2008, does not support .NET 4.0.&lt;BR /&gt;Time for an upgrade.&lt;BR /&gt;Thanks for all your help.</description>
      <pubDate>Fri, 14 Feb 2014 20:01:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/thumbnail-ocx-for-net-64-bit/m-p/4816923#M45406</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-02-14T20:01:56Z</dc:date>
    </item>
  </channel>
</rss>

