Results 1 to 15 of 15

Thread: [RESOLVED] Help finding old code sample here on VBF

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Resolved [RESOLVED] Help finding old code sample here on VBF

    Hi everyone!

    I've searched the forums here for several days and can't find this. I had it in my own personal use codebank but I went through a hard drive crash and lost lots of things .



    There was posted a simple example of using IStream and GDI+ in order to retrieve and save video file thumbnails. Not sure but I think that the author was either dilettante or fafalone. Not sure if it was in the codebank here or just in a post.

    I would love to find that again because it was great code and I have a need. Any help appreciated. Thank you .

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,892

    Re: Help finding old code sample here on VBF

    This? https://www.vbforums.com/showthread....umbnail-Images

    Btw if you don't like the shell object (I don't), you can get the same property via

    Code:
    Dim pItem As IShellItem2
    Dim vProp As Variant
    SHCreateItemFromParsingName StrPtr(path), Nothing, IID_IShellItem2, pItem
    pItem.GetProperty PKEY_ThumbnailStream, vProp
            If VarType(vProp) = VT_STREAM Then 
                Dim vt As Integer
                vt = VT_UNKNOWN
                CopyMemory ByVal VarPtr(vProp), ByVal VarPtr(vt), 2&
    (with oleexp.tlb+mIID.bas)

    Then whatever the other code or your own code wants to do with the IStream-containing Variant.

    FWIW, it's the 4th result down (using the Enhanced by Google search) for 'video thumbnail'...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    No, wasn't that one. You're right, I could do it that way and maybe will. My project now uses the shell object to get video thumbs and its working fast & perfect but I wanted to have a fallback in case user has thumbnails disabled on their system. The example that I can't find was perfect. I can write it myself too but I really liked the way that that was doing things.....

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    Actually I should say that I liked the simplicity & elegance of that code. I'm reasonably sure that you wrote it.....

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,289

    Re: Help finding old code sample here on VBF

    Have you tried, using the cGDIPlusCache - DropIn-Class for that?
    https://www.vbforums.com/showthread....=1#post5446043

    With it, you can influence the size of the retrieved thumbnail, as well as its later "positional rendering" -
    and of course also PNG-export (as well as internal caching) are covered...

    Olaf

  6. #6
    Addicted Member
    Join Date
    Jul 2021
    Posts
    201

    Re: Help finding old code sample here on VBF

    BTW, you don't need GDI+ for this. It is possible to do it using plain GDI functions.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    Quote Originally Posted by Schmidt View Post
    Have you tried, using the cGDIPlusCache - DropIn-Class for that?
    https://www.vbforums.com/showthread....=1#post5446043

    With it, you can influence the size of the retrieved thumbnail, as well as its later "positional rendering" -
    and of course also PNG-export (as well as internal caching) are covered...

    Olaf
    Yes sir I have and I'm using that great class with minor modifications in some of my programs. It does a wonderful job of loading, cacheing, and rendering from the shell. I don't need to save the image to disk, only mentioned it because it was in that other sample.

    My objective is to use a stream to get video thumbnails as a fallback to the shell in case the end user has shell thumbnails disabled on their system. So program flow is shell 1st via cGDIPlusCache, fallback to stream method if needed. I could probably write such into my copy of the class.....

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,892

    Re: Help finding old code sample here on VBF

    That method works with thumbnails disabled... but I'm not sure what else you could mean that uses IStream and GDI+. Loading the file itself into an IStream would be redundant when you can just pass the path directly to GDI+.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    Quote Originally Posted by fafalone View Post
    That method works with thumbnails disabled... but I'm not sure what else you could mean that uses IStream and GDI+. Loading the file itself into an IStream would be redundant when you can just pass the path directly to GDI+.
    Dang I wish my SSD HD hadn't crashed about 2 weeks ago or I could repost that sample and show you what I'm talking about. I'm going to poke around in my backups again and see if I missed it.....

  10. #10
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,892

    Re: Help finding old code sample here on VBF

    It's by dilettante originally, I posted a oleexp-based version, it uses IStream and GDI+... but you're thinking of a *different* video thumbnail project, also likely by me or dilettante, also using IStream and GDI+? You *sure* it's not that one or one of the modified versions posted in that thread? LOL

    Are you sure about GDI+? There's other methods with IStream + WIA.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    Quote Originally Posted by fafalone View Post
    It's by dilettante originally, I posted a oleexp-based version, it uses IStream and GDI+... but you're thinking of a *different* video thumbnail project, also likely by me or dilettante, also using IStream and GDI+? You *sure* it's not that one or one of the modified versions posted in that thread? LOL

    Are you sure about GDI+? There's other methods with IStream + WIA.
    Yup it needs to use GDI+ if possible so as to interface with my present GDI+ based everything. The sample to which I'm referring was just a little code blurb in a post. No download, just copy & paste. If I remember, it had some form code and a small module. The GDI+ stuff was only there for saving the video thumbnail to disk which I don't need, so I was going to modify it and use the resulting GDI+ handle to draw the thumbnail instead.

    Geez, now I'm thinking that I dreamed the whole thing!

    EDIT: I'm pretty sure that no WIA was involved which is what attracted me to it but could be wrong...
    Last edited by SomeYguy; Apr 18th, 2024 at 03:00 PM.

  12. #12
    Addicted Member -Franky-'s Avatar
    Join Date
    Dec 2022
    Location
    Bremen Germany
    Posts
    249

    Re: Help finding old code sample here on VBF

    There are so many ways to create a thumbnail from a video. About the IPropertyStore, or about IShellItem2.GetProperty, has already been mentioned. IShellItemImageFactory and IExtractImage would be other options. There may also be an option via MediaFoundation.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    Such is true. I was just looking for that old post because the code there was pretty much plug 'n play with my own GDI+ code. No worries, I can write something non-shellitem based if needed.....

  14. #14
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,892

    Re: Help finding old code sample here on VBF

    Code:
        Public Declare Function GdipCreateBitmapFromStream Lib "gdiplus" (ByVal stream As IStream, ByRef bitmap As LongPtr) As GpStatus
    
    Public Function GetGDIPBitmapFromThumbStream(sFile As String) As LongPtr
    Dim pItem As IShellItem2
    Dim vProp As Variant
    Dim hGBmp As LongPtr
    SHCreateItemFromParsingName StrPtr(sFile), Nothing, IID_IShellItem2, pItem
    pItem.GetProperty PKEY_ThumbnailStream, vProp
            If VarType(vProp) = VT_STREAM Then 
                Dim vt As Integer
                vt = VT_UNKNOWN
                CopyMemory ByVal VarPtr(vProp), ByVal VarPtr(vt), 2&
    
                GdipCreateBitmapFromStream vProp, hGBmp
                GetGDIPBitmapFromThumbStream = hGBmp
            End If
    End Function
    
    'Exclude the following if you have mPKEY.bas added:
    Public Function PKEY_ThumbnailStream() As PROPERTYKEY
    Static pkk As PROPERTYKEY
     If (pkk.fmtid.Data1 = 0&) Then Call DEFINE_PROPERTYKEY(pkk, &HF29F85E0, &H4FF9, &H1068, &HAB, &H91, &H8, &H0, &H2B, &H27, &HB3, &HD9, 27)
    PKEY_ThumbnailStream = pkk
    End Function
    Private Sub DEFINE_PROPERTYKEY(Name As PROPERTYKEY, L As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte, pid As Long)
      With Name.fmtid
        .Data1 = L: .Data2 = w1: .Data3 = w2: .Data4(0) = B0: .Data4(1) = b1: .Data4(2) = b2: .Data4(3) = B3: .Data4(4) = b4: .Data4(5) = b5: .Data4(6) = b6: .Data4(7) = b7
      End With
      Name.pid = pid
    End Sub
    A GDI+ bitmap handle should be plug and play with your own GDI+ code as much as I can imagine; and as mentioned, this works with thumbnail view off (I use it for that too).
    It uses oleexp.tlb and mIID.bas.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2015
    Posts
    176

    Re: Help finding old code sample here on VBF

    Quote Originally Posted by fafalone View Post
    Code:
        Public Declare Function GdipCreateBitmapFromStream Lib "gdiplus" (ByVal stream As IStream, ByRef bitmap As LongPtr) As GpStatus
    
    Public Function GetGDIPBitmapFromThumbStream(sFile As String) As LongPtr
    Dim pItem As IShellItem2
    Dim vProp As Variant
    Dim hGBmp As LongPtr
    SHCreateItemFromParsingName StrPtr(sFile), Nothing, IID_IShellItem2, pItem
    pItem.GetProperty PKEY_ThumbnailStream, vProp
            If VarType(vProp) = VT_STREAM Then 
                Dim vt As Integer
                vt = VT_UNKNOWN
                CopyMemory ByVal VarPtr(vProp), ByVal VarPtr(vt), 2&
    
                GdipCreateBitmapFromStream vProp, hGBmp
                GetGDIPBitmapFromThumbStream = hGBmp
            End If
    End Function
    
    'Exclude the following if you have mPKEY.bas added:
    Public Function PKEY_ThumbnailStream() As PROPERTYKEY
    Static pkk As PROPERTYKEY
     If (pkk.fmtid.Data1 = 0&) Then Call DEFINE_PROPERTYKEY(pkk, &HF29F85E0, &H4FF9, &H1068, &HAB, &H91, &H8, &H0, &H2B, &H27, &HB3, &HD9, 27)
    PKEY_ThumbnailStream = pkk
    End Function
    Private Sub DEFINE_PROPERTYKEY(Name As PROPERTYKEY, L As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte, pid As Long)
      With Name.fmtid
        .Data1 = L: .Data2 = w1: .Data3 = w2: .Data4(0) = B0: .Data4(1) = b1: .Data4(2) = b2: .Data4(3) = B3: .Data4(4) = b4: .Data4(5) = b5: .Data4(6) = b6: .Data4(7) = b7
      End With
      Name.pid = pid
    End Sub
    A GDI+ bitmap handle should be plug and play with your own GDI+ code as much as I can imagine; and as mentioned, this works with thumbnail view off (I use it for that too).
    It uses oleexp.tlb and mIID.bas.

    Thank you! - After looking at this i'm 99% sure that its the same thing as that old post but without the save to disk part which I don't need. I just need the bitmap handle so its great. Thanks again and I will mark this resolved .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width