从UWP App获取图标 [英] Get Icon from UWP App

查看:140
本文介绍了从UWP App获取图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提取UWP应用的图标以构建类似打开方式"菜单的资源管理器.

I want to extract the icon of an UWP App to build a Explorer like "Open With" menue.

借助 SHAssocEnumHandlers 我设法将相关的应用程序扩展到给定的文件扩展名.

With the help of SHAssocEnumHandlers i managed to get the associated applications to a given file extension.

使用 IAssocHandler :: GetIconLocation 我为UWP Apps(Microsoft Edge)获得了类似的东西:

With IAssocHandler::GetIconLocation i get for UWP Apps (Microsoft Edge) something like:

@ {Microsoft.MicrosoftEdge_41.16299.371.0_neutral__8wekyb3d8bbwe?ms-resource://Microsoft.MicrosoftEdge/Files/Assets/MicrosoftEdgeSquare44x44.png}

@{Microsoft.MicrosoftEdge_41.16299.371.0_neutral__8wekyb3d8bbwe?ms-resource://Microsoft.MicrosoftEdge/Files/Assets/MicrosoftEdgeSquare44x44.png}

如果我使用 SHLoadIndirectString 在此字符串上我得到:

If i use SHLoadIndirectString on this string i get:

C:\ WINDOWS \ SystemApps \ Microsoft.MicrosoftEdge_8wekyb3d8bbwe \ Assets \ MicrosoftEdgeSquare44x44.scale-100.png

C:\WINDOWS\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\Assets\MicrosoftEdgeSquare44x44.scale-100.png

但这是错误的图标(没有颜色或对比度).

But that is the wrong Icon (has no color or contrast).

在目录中:

C:\ WINDOWS \ SystemApps \ Microsoft.MicrosoftEdge_8wekyb3d8bbwe \ Assets \

C:\WINDOWS\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\Assets\

有很多不同的图像. 我不明白如何选择正确的图标.

Are a lot of different Images. I don't understand how to choose the correct icon.

我试图查找"AppxManifest.xml",但是对于不同的应用程序,我看起来完全不同.

I tried to look up the "AppxManifest.xml" but i looks completly different for different Apps.

对于非UWP应用,我得到的图标位置为:

For an non UWP App i get as IconLocation something like:

C:\ WINDOWS \ system32 \ NOTEPAD.EXE

C:\WINDOWS\system32\NOTEPAD.EXE

然后我可以使用:

Icon.ExtractAssociatedIcon()

,一切都很好.我找不到使用UWP App进行此操作的任何方法.

and everything is fine. I didn't finde any way to do the same with an UWP App.

推荐答案

UWP应用程序(或Windows Store应用程序,或有时称为"AppX应用程序模型"的应用程序)信息可从官方API查询.

UWP apps (or Windows Store apps, or apps in what's called sometimes the "AppX application model") information can be queried from official APIs.

这些API没有等效的C#AFAIK,但是我在SO上对类似问题的回答中提供了示例代码来做到这一点:

These APIs don't have a C# equivalent AFAIK but I've provided sample code to do this in my answer to a similar question here on SO: Getting icon of "modern" Windows app from a desktop application?

该示例应用程序转储了所有当前已加载的Windows应用商店软件包&应用.

The sample application dumps all current loaded Windows Store packages & apps.

请注意,UWP应用程序不仅有一个一个图标,而且可能有许多图标可以适应特定的设备,外形等.示例代码中的实用程序可以给定资源的最大比例图像.

Note there is not just one icon for a UWP app, there may be many, to be able to adapt to a specific device, form factors, etc. The sample code has a utility that gets the highest scale image for a given resource.

这篇关于从UWP App获取图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆