creating thumbnails from files

mcgilles
03-12-2006, 10: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.

by_m
03-17-2006, 02: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...

jo0ls
03-17-2006, 06: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.

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

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

jo0ls
03-22-2006, 08:51 PM
ah a complicated way (http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/article.asp)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum