Other Posts in Image Editing

  1. Perlin Noise
  2. Fault Formation
  3. Cellular Textures
  4. Resizing an Image in C#
  5. Box Blur and Gaussian Blur... Sort of...
  6. Thermal Erosion
  7. Using Mid Point Displacement to Create Cracks
  8. Fluvial Erosion
  9. Creating Marble Like Textures Procedurally
  10. Procedural Textures and Dilation
  11. Converting Image to Black and White in C#
  12. Getting an HTML Based Color Palette from an Image in C#
  13. Adding Noise/Jitter to an Image in C#
  14. Creating Pixelated Images in C#
  15. Edge detection in C#
  16. Using Sin to Get What You Want... In C#...
  17. Noise Reduction of an Image in C# using Median Filters
  18. Image Dilation in C#
  19. Sepia Tone in C#
  20. Kuwahara Filter in C#
  21. Matrix Convolution Filters in C#
  22. Symmetric Nearest Neighbor in C#
  23. Bump Map Creation Using C#
  24. Normal Map Creation Using C#
  25. Creating Negative Images using C#
  26. Red, Blue, and Green Filters in C#
  27. Converting an Image to ASCII Art in C#
  28. Adjusting Brightness of an Image in C#
  29. Adding Noise to an Image in C#
  30. Adjusting the Gamma of an Image Using C#
  31. Adjusting Contrast of an Image in C#
  32. Drawing a Box With Rounded Corners in C#
  33. Anding Two Images Together Using C#
  34. Motion Detection in C#
  35. Creating Thermometer Chart in C#
  36. Colorizing a Black and White Image in C#
  37. Extracting an Icon From a File
  38. Setting the Pixel Format and Image Format of an Image in .Net
  39. Using Unsafe Code for Faster Image Manipulation
  40. Sobel Edge Detection and Laplace Edge Detection in C#

Extracting an Icon From a File


I had a function a while back that would enumerate images within a DLL and another that would extract one. It was never really all that useful but it did give me a couple hours of fun searching through various DLLs. This was back in the days when everyone was trying to learn C++ (and yes, was written in C++). So why does this little story matter? Well I was bored today and wondered how easy it would be to do a similar thing in C#. Which led me to something even more useful. Extracting the icon associated with a file type:

   1: /// <summary>
   2: /// Extracts an icon associated with a file
   3: /// </summary>
   4: /// <param name="FileName">File to extract the icon from</param>
   5: /// <returns>Returns the extracted icon</returns>
   6: public static Bitmap ExtractIcon(string FileName)
   7: {
   8:     return System.Drawing.Icon.ExtractAssociatedIcon(FileName).ToBitmap();
   9: }

That's it. One line of code and you can get the icon associated with a file. I remember doing something similar took me a couple hundred lines... And I had to walk up hill to the punch card reader... Both ways... Kids today have it easy. Although no idea why I used punch cards considering I'm in my 20s... Anyway, I hope you can find some use for that bit of code. So try it out, leave feedback, and happy coding.