Skip to content

Icon.ExtractAssociatedIcon should return an icons descriptor #14647

@jez9999

Description

@jez9999

Background and motivation

Right now, the Icon.ExtractAssociatedIcon method can be used to get one and only one of the icons associated with a certain file, but the file is likely to have multiple icons of different sizes and color depths associated with it. I think this method or a new similar method should return some kind of "icons descriptor" where you can iterate through every icon associated with the file specified. I notice some work was done in issue #8929 to add ExtractIcon but that really tackles a different problem of extracting an icon from the file actually containing the icon resource and not a file just associated with it. Basically I want to be able to pass in a .pdf file and get all the icons associated with PDF files on the system.

API Proposal

namespace System.Drawing;

public class Icon
{
    // The existing Extract method.
    public static Icon ExtractAssociatedIcon(string! filePath);

    // New method to get all icons
     public static IconsDescriptor ExtractAssociatedIcons(string! filePath);
}

API Usage

// Get icons descriptor
using IconsDescriptor icons = Icon.ExtractAssociatedIcons(@"C:\Path\To\my.pdf");
// e.g. save all icons to their own file
foreach (var icon in icons.AllIcons) {
    using (var outputFileHandle = getNewIconHandle()) {
        icon.Save(outputFileHandle);
    }
}

Alternative Designs

No response

Risks

No response

Will this feature affect UI controls?

No.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestion(1) Early API idea and discussion, it is NOT ready for implementationuntriagedThe team needs to look at this issue in the next triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions