Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Best way to get and save a thumbnail

$
0
0

My application is using File System Watcher, to monitor file changes, and when the application settings allow, backing up the file to an external server. I am unsure of the best way to get the thumbnail image for the file that triggers the changed event, and then convert that image to a base64 string for easy storage in my database. I have the rest of the monitoring and file conversion/storage done. I am developing this using vb.net, but I needed a WPF specific answer. I know you can get the thumbnail using something similar to this in WinForms:

    Private Function GetThumbnail(ByVal path As String) As Image

        Try
            '################
            Dim strm As Stream = New FileStream(path.Trim, FileMode.Open, FileAccess.Read, FileShare.Read)
            Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(strm, False, False)

            If Array.IndexOf(img.PropertyIdList, THUMBNAIL_DATA) > -1 Then
                Dim item1 As PropertyItem = img.GetPropertyItem(THUMBNAIL_DATA)
                strm.Close()
                img.Dispose()
                Dim buffer1 As Byte() = item1.Value
                strm = New MemoryStream(buffer1.Length)
                strm.Write(buffer1, 0, buffer1.Length)

                    Return img System.Drawing.Image.FromStream(strm)
            Else
                Return Nothing
            End If
            '################
        Catch ex As Exception
            Throw ex
        End Try

    End Function


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>