I do not speak English and maybe I'm wrong or not understand the issue.
But if you need to read the preview image without using AutoCAD you can use this:
(Also works with 32-bit images (Yes, thumbnail may be 32-bit), 100% dotNet)
Imports System
Imports System.Drawing
Imports System.IO
Friend NotInheritable Class ThumbnailReader
<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Private Structure tagBITMAPFILEHEADER
Public bfType As UShort
Public bfSize As UInteger
Public bfReserved1 As UShort
Public bfReserved2 As UShort
Public bfOffBits As UInteger
End Structure
Friend Shared Function GetThumbnail(ByVal filename As String) As Bitmap
Using fs As FileStream = File.OpenRead(filename)
Using br As BinaryReader = New BinaryReader(fs)
Dim datLoc As Integer
Dim bytCnt As Byte
' TODO
' Modificar para leer directamente el centinela
fs.Seek(13, SeekOrigin.Begin)
datLoc = br.ReadInt32()
datLoc += 20
fs.Seek(datLoc, SeekOrigin.Begin)
bytCnt = br.ReadByte()
If bytCnt <= 1 Then
Return Nothing
End If
Dim imgHeaderStart As Int32
Dim imgHeaderSize As Int32
Dim imgCode As Byte
For i As Short = 1 To bytCnt
imgCode = br.ReadByte()
imgHeaderStart = br.ReadInt32()
imgHeaderSize = br.ReadInt32()
If imgCode = 2 Then
fs.Seek(imgHeaderStart, SeekOrigin.Begin)
'-----------------------------------------------------
' TODO
' Deberia comprobar si asi es mas rapido, o leer cada bloque uno a uno
Dim bmpHeader(40) As Byte
bmpHeader = br.ReadBytes(40)
Dim biBitCount As UShort = BitConverter.ToUInt16(New Byte() {bmpHeader(14), bmpHeader(15)}, 0)
Dim biSizeImage As UInteger = BitConverter.ToUInt16(New Byte() {bmpHeader(20), bmpHeader(21), bmpHeader(22), bmpHeader(23)}, 0)
'-----------------------------------------------------
fs.Seek(imgHeaderStart, SeekOrigin.Begin)
Dim bytBMPBuff(imgHeaderSize) As Byte
bytBMPBuff = br.ReadBytes(imgHeaderSize)
Dim clrTableSize As UInteger = CUInt(If(biBitCount < 9, 4 * (2 ^ biBitCount), 0))
Dim bfHeader As tagBITMAPFILEHEADER
With bfHeader
.bfType = &H4D42
.bfSize = CUInt(54) + clrTableSize + biSizeImage
.bfOffBits = CUInt(54) + clrTableSize
End With
Using ms As New MemoryStream
Using bw As BinaryWriter = New BinaryWriter(ms)
bw.Write(bfHeader.bfType)
bw.Write(bfHeader.bfSize)
bw.Write(bfHeader.bfReserved1)
bw.Write(bfHeader.bfReserved2)
bw.Write(bfHeader.bfOffBits)
bw.Write(bytBMPBuff)
Dim bm As Bitmap = New Bitmap(ms)
Return bm
End Using
End Using
ElseIf imgCode = 3 Then
Return Nothing
End If
Next
End Using
End Using
Return Nothing
End Function
End Class