
Update for Vault 2012: Additional image formats supported. This post applies to Vault 2011 and earlier. Go here for the Vault 2012 code.

Here is how you view thumbnail data from Vault.
Background:
Thumbnails are stored as metafiles, which must be rendered to a display context. This is a bit different from a jpeg because metafiles have no fixed size. This is nice because the image can be scaled to any size without loss of detail.
Sample Code:
Once you have found the PropInst object with the thumbnail value, here is how you can render it to a System.Drawing.Image object.
C#:
| /// <summary> /// Takes a thumbnail property from Vault and renders it to an Image /// </summary> private System.Drawing.Image RenderThumbnailToImage(Document.PropInst propInst, int width, int height) { // convert the property value to a byte array byte[] thumbnailRaw = (byte[])propInst.Val; // load the data into a stream but skip the first 12 bytes // create the Metafile object // render the Metafile to an Image object and display in the picture box /// <summary> |
VB.NET:
| ''' <summary> ''' Takes a thumbnail property from Vault and renders it to an Image ''' </summary> Private Function RenderThumbnailToImage(ByVal propInst As Document.PropInst, ByVal width As Integer, ByVal height As Integer) As System.Drawing.Image ' convert the property value to a byte array ' load the data into a stream but skip the first 12 bytes ' create the Metafile object ' render the Metafile to an Image object and display in the picture box stream.Close() End Function ''' <summary> ''' Delagate for the GetThumnailImage function. ''' </summary> Private Shared Function GetThumbnailImageAbort() As Boolean Return False ' do nothing End Function |


Leave a Reply