Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Thumbnail from Vault

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
joerituijn
584 Views, 3 Replies

Thumbnail from Vault

Hi, I'm trying to get the thumbnail from vault (2013). I found some code from Doug but can't get it to work. It fails on this line;

 

Dim im As Image = Image.FromStream(stream)

 

I can add/change the arguments (true, false) but that doesn't make a difference. It gives me an argument exception (A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll). What's wrong?

 

The code: 

Dim PropInsts() As PropInst = PropSvc.GetProperties("FILE", New Long() {File.Id}, New Long() {ThumbProp.Id})

If Not PropInsts Is Nothing Then 

If PropInsts(0).Val Is Nothing Then Return Nothing

 

Dim retVal As Image = Nothing

 

' convert the property value to a byte array
Dim thumbnailRaw As Byte() = DirectCast(PropInsts(0).Val, Byte())

 

' load the data into a stream but skip the first 12 bytes
Using stream As New IO.MemoryStream(thumbnailRaw, 12, thumbnailRaw.Length - 12)
Using br As New System.IO.BinaryReader(stream)
Dim CF_METAFILEPICT As Integer = 3
Dim CF_ENHMETAFILE As Integer = 14

Dim clipboardFormatId As Integer = br.ReadInt32()
Dim bytesRepresentMetafile As Boolean = (clipboardFormatId = CF_METAFILEPICT OrElse clipboardFormatId = CF_ENHMETAFILE)
Try

If bytesRepresentMetafile Then
' the bytes represent a clipboard metafile

' read past header information
br.ReadInt16()
br.ReadInt16()
br.ReadInt16()
br.ReadInt16()

Dim mf As New System.Drawing.Imaging.Metafile(br.BaseStream)
retVal = mf.GetThumbnailImage(width, height, New Image.GetThumbnailImageAbort(AddressOf GetThumbnailImageAbort), IntPtr.Zero)
Else
' the bytes do not represent a metafile, try to convert to an Image
stream.Seek(0, System.IO.SeekOrigin.Begin)
Dim im As Image = Image.FromStream(stream)

retVal = im.GetThumbnailImage(width, height, New Image.GetThumbnailImageAbort(AddressOf GetThumbnailImageAbort), IntPtr.Zero)
End If
Catch : End Try

End Using
End Using

 

Return retVal

End If

3 REPLIES 3
Message 2 of 4
joerituijn
in reply to: joerituijn

I discovered that the problem lies here:

 

Using stream As New IO.MemoryStream(thumbnailRaw, 12, thumbnailRaw.Length - 12)

 

Remove the starting point and it works fine:

 

Using stream As New IO.MemoryStream(thumbnailRaw, 0, thumbnailRaw.Length)

 

The question remains; why? Does this work on every PC? I'm using win7/64bit...

Message 3 of 4
Redmond.D
in reply to: joerituijn

The part that chops off the first 12 bytes of the MemoryStream is probably resulting in an invalid Image.  I recently posted some updated code, so try that.



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 4 of 4
joerituijn
in reply to: Redmond.D

That's what I figured, thanks anyway!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report