creating thumbnails from files

03-12-2006, 11:59 PM
I would like to be able to put a thumbnail view of a file into a picture box on a VB.NET program. there is plenty of information on how to do this with pictures, or even pdfs tht I have found already. but I would like to be able to do this with almost any file, just like in the thumbnails view in windows, to show me pictures, pdfs, videos, word docs...all the common file types as a small thumbnail in a program. or display the icon assigned to that file type by windows otherwise. is there any easy way to do this? I may have to just create thumbnails from the few types I can find code for online, but since windows does it, I can't help but thinking there would be a way to do this the same way windows does.

03-17-2006, 03:43 PM
I guess this is related to your other post, but in short, if you want to show the actual file content as a thumbnail you would code it on a per file type basis. What windows does is just display the icon associated with that file, but you already knew that...

03-17-2006, 07:28 PM
Windows uses the thumbs.db file. This has an undocumented format, some people have poked about and found that it is a structured storage file, containing images in some jpg like format but missing a color table.
To get the icons for files you can use windows apis. For exes use ExtractIconEx, for others use SHGetFileInfo.
To get thumbnails for images then, you can use GDI+. Images (System.Drawing.Image) have a getthumnail method. This is good for small sizes. But, it stretches to fit. The view in windows explorer is scaled and centered, and on a backcolor, and with a frame. So there is a bit more work to do...
See attached example (2005, if you have 2003 then it is all in form1.vb so read that)

edit. hmm not much point using ExtractIconEx for exes, as SHGetFileInfo gets from exe files too.

03-19-2006, 01:13 PM
Ah, there is a .Net method:

Dim ico As Icon = Icon.ExtractAssociatedIcon("C:\WINDOWS\system32\notepad.exe")

03-22-2006, 09:51 PM
ah a complicated way (

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum