Get thumbnail from BOM or File using Apprentice from background worker og thread
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
We are trying to access Inventor file information such as iproperties and thumbnail.
in our old softawre we godt the thumbnail from iProperties using aprentice running in main thread, and that worked just fine.
In the new software we are using a background worker and threading to speed up the process of getting and analyzing data.
this works just find for all iProperties except for the thumbnail. we have tried to get the Thumbnail from iProperties and directly from Doc.Thumbnail but both methods fires an exception.
we have made a method to get the thumbnail using ShellFile as seen below. but this method is a lot slower than using apprentice.
Private Function GetThumbnailBytes(filename As String, prop As InvPropertyDef, desiredHeight As Integer) As InvProperty
Dim result As New InvProperty With {.Id_InvPropertyDef = prop.Id, .Name = prop.Name}
Dim thumbnailBytes As Byte()
Using sfile As ShellFile = ShellFile.FromFilePath(filename)
Dim thumbBmp As Bitmap = Nothing
thumbBmp = If(desiredHeight > 256, sfile.Thumbnail.ExtraLargeBitmap, sfile.Thumbnail.LargeBitmap) '.ExtraLargeBitmap
'Dim thumbBmp2 As Bitmap = sfile.Thumbnail.LargeBitmap
'Dim thumbBmp3 As Bitmap = sfile.Thumbnail.SmallBitmap
'compute new width
Dim Ratio As Double = CDbl(thumbBmp.Width / thumbBmp.Height)
Dim height As Integer = desiredHeight
Dim width As Integer = CInt(height / Ratio)
'resize
Using resizedBmp As Bitmap = New Bitmap(thumbBmp, width, height)
Using ms As MemoryStream = New MemoryStream()
resizedBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
thumbnailBytes = ms.ToArray()
End Using
End Using
End Using
result.ImageValue = thumbnailBytes
Return result
End Function
Have anyone else tried to get the thumbnail using Apprentice or Inventor from a Background workers and/or Threading?