none
how to extract a large icon from a file (WPF)

    Question

  • Hello

    I need to extract the associate icon from files.

    Browsing on internet i managed to fine the following code:


     

     

    Sub b(ByRef address As String)

    Dim ico As IconImage = IconImage.ExtractAssociatedIcon(address)
    Dim bmp As System.Drawing.Bitmap = ico.ToBitmap()
    Dim ms As MemoryStream = New MemoryStream()
    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
    Dim bmpImage As BitmapImage = New BitmapImage()
    bmpImage.BeginInit()
    ms.Seek(0, SeekOrigin.Begin)
    bmpImage.StreamSource = ms
    bmpImage.EndInit()
    Image1.Source = bmpImage

    End Sub

     

     

     


    Everything works fine a part that the icon is the smal one

    how can i get the large icon?

    • Edited by marck68 Wednesday, May 06, 2009 3:34 PM
    Wednesday, May 06, 2009 3:34 PM

Answers

  • Hello marck68,
    I currently use the decoder to go throught he frames and pick the one I want. You are just getting the first frame of the icon. Here is an example:

    myIconBitmapDecoder = new IconBitmapDecoder(new Uri(@"pack://application:,,/Resources/myIcon.ico"), BitmapCreateOptions.None, BitmapCacheOption.Default);
    
    ImageSource myImageSource = myIconBitmapDecoder.Frames[0];
    or
    ImageSource myImageSource= myIconBitmapDecoder.Frames[n]; <-- where n is the correct frame number you need
    Image myImage = new Image();
    myImage.Source = myImageSource;
    Hope this helps.
    noorbakhsh
    Wednesday, May 06, 2009 3:42 PM

All replies

  • Hello marck68,
    I currently use the decoder to go throught he frames and pick the one I want. You are just getting the first frame of the icon. Here is an example:

    myIconBitmapDecoder = new IconBitmapDecoder(new Uri(@"pack://application:,,/Resources/myIcon.ico"), BitmapCreateOptions.None, BitmapCacheOption.Default);
    
    ImageSource myImageSource = myIconBitmapDecoder.Frames[0];
    or
    ImageSource myImageSource= myIconBitmapDecoder.Frames[n]; <-- where n is the correct frame number you need
    Image myImage = new Image();
    myImage.Source = myImageSource;
    Hope this helps.
    noorbakhsh
    Wednesday, May 06, 2009 3:42 PM
  • I need to get the icon associated to a file

    how can I pass the file address and get the icon with the code you have presented above?

    Wednesday, May 06, 2009 4:16 PM
  • I am trying to use thsi code

    Dim

     

    ico As IconImage = IconImage.ExtractAssociatedIcon(address)
    Dim ms As MemoryStream = New MemoryStream()
    ico.Save(ms)
    Dim myIconBitmapDecoder As New IconBitmapDecoder(ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad)
    Dim myImageSource As ImageSource = myIconBitmapDecoder.Frames(0)
    Image1.Source = myImageSource

    but i get just one icon and the quality is horrible

    Wednesday, May 06, 2009 4:32 PM
  • Well you need to check the other frames. You are using the image in frame zero "myIconBitmapDecoder.Frames(0)".
    How many frames does your icon have? Try 1 or 2 or easch one till you get what you want.


    noorbakhsh
    Wednesday, May 06, 2009 4:47 PM
  • it has just on frame
    Wednesday, May 06, 2009 4:57 PM