我们如何获取用户在Windows7和WIndows 8中使用的头像?(我主要想在Windows8上使用它)。到目前为止,我只看到一堆论坛帖子说这不能做到,但我看到左右和中心的应用程序可以做到这一点。
发布于 2013-06-04 04:00:52
此blog post显示如何设置用户磁贴(图片)。在接近尾声的评论中(Michael Anthony,Apr 10,22:45),评论者描述了如何获得图片。我已经将这些信息收集到一个C#片段中。请记住,这是基于一个未记录的Windows Shell函数。
using System;
using System.Text;
using System.Drawing;
[DllImport("shell32.dll", EntryPoint = "#261",
CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void GetUserTilePath(
string username,
UInt32 whatever, // 0x80000000
StringBuilder picpath, int maxLength);
public static string GetUserTilePath(string username)
{ // username: use null for current user
var sb = new StringBuilder(1000);
GetUserTilePath(username, 0x80000000, sb, sb.Capacity);
return sb.ToString();
}
public static Image GetUserTile(string username)
{
return Image.FromFile(GetUserTilePath(username));
}请注意,此外壳函数创建文件\Users\\AppData...\.bmp并返回其文件名。
另外,我已经在Win7上测试过了。我不知道它与以前的Windows版本的兼容性。
感谢Joco和Michael Anthony。
https://stackoverflow.com/questions/16904251
复制相似问题