user817759
user817759

Reputation: 111

Creating thumbnail previews in VB.NET

I'm trying to create thumbnail previews within my program. These would work for any file type, not only images. So videos too. Right now I'm using IExtractImage to do this. It works perfect, but it seems to randomly crash my program when I call .Extract(). There's no error message, my program just crashes. When I run it in the debugger it doesn't break when it crashes. I have it in a try/catch block and that doesn't seem to help. It's not reproducible and doesn't crash on the same file every time. How can I get it working or just prevent it from crashing my whole program?

I'm using the code from this project:

http://www.vbaccelerator.com/home/net/code/libraries/shell_projects/Thumbnail_Extraction/article.asp

Upvotes: 0

Views: 5466

Answers (1)

David C
David C

Reputation: 3810

So if you run the application in debug mode, take it out of the try/catch block and you get no error at all? What happens when the application crashes, is there an exception message?. If you are still not getting an exception at all, I am not sure what to make of that. I am guessing it has something to do with an exception in the unmanaged windows code not being thrown or bubbled back up correctly.

Instead of using the shell code from the post you referenced, you could use Image.GetThumbnail from the .NET framework for images (very simple), and a call to direct show to grab thumbnails for any supported video types.

Image :

// create an image object, using the filename of the file
   System.Drawing.Image image = System.Drawing.Image.FromFile(filename);

// create the actual thumbnail image
   System.Drawing.Image thumbnailImage = image.GetThumbnailImage(64, 64, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

   public bool ThumbnailCallback()
     {
       return true;
     }

Video :

Check the post at : Video Thumbnail Creator

Upvotes: 1

Related Questions