
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 Stream stream = new MemoryStream(thumbnailRaw, 12, thumbnailRaw.Length - 12); // create the Metafile object System.Drawing.Imaging.Metafile metafile = new System.Drawing.Imaging.Metafile(stream); // render the Metafile to an Image object and display in the picture box Image retVal = metafile.GetThumbnailImage(width, height, new Image.GetThumbnailImageAbort(GetThumbnailImageAbort), IntPtr.Zero); stream.Close(); return retVal; }
|
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 Dim thumbnailRaw As Byte() = CType(propInst.Val, Byte()) ' load the data into a stream but skip the first 12 bytes Dim stream As System.IO.Stream = New System.IO.MemoryStream(thumbnailRaw, 12, thumbnailRaw.Length - 12) ' create the Metafile object Dim metafile As System.Drawing.Imaging.Metafile = New System.Drawing.Imaging.Metafile(stream) ' render the Metafile to an Image object and display in the picture box Dim retVal As Image = metafile.GetThumbnailImage(width, height, New Image.GetThumbnailImageAbort(AddressOf GetThumbnailImageAbort), IntPtr.Zero) stream.Close() Return retVal End Function ''' <summary> ''' Delagate for the GetThumnailImage function. ''' </summary> Private Shared Function GetThumbnailImageAbort() As Boolean Return False ' do nothing End Function |


Subscribe