dotnet / dotnet/winforms

Icon.ExtractAssociatedIcon should return an icons descriptor

Open
#14,647 0 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-System.Drawing untriaged
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### 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

```csharp
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

```csharp
// 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.