1

I'm trying to get windows user profile picture from C:\ProgramData\Microsoft\User Account Pictures\{UserName}.dat by this code:

public static Image GetUserimage()
{
    if (File.Exists(@"C:\ProgramData\Microsoft\User Account Pictures\" + Environment.UserName + ".dat"))
    {
        return Image.FromFile(@"C:\ProgramData\Microsoft\User Account Pictures\" + Environment.UserName + ".dat");
    }
    else
    {
        return Cheat.Properties.Resource1.Image1;
    }
}

But I get this error when trying to call it pictureBox1.Image = GetUserimage();:

System.OutOfMemoryException: 'Out of memory.'

And I think the reason is .dat is not image file to use it as image.

So my question is HOW TO CONVERT .dat FILE TO IMAGE FORMAT TO USE IT AS IMAGE VAR ?

Jackdaw
  • 7,626
  • 5
  • 15
  • 33

2 Answers2

1

On Windows 10/11, you can get a user's profile directly through the WinRT API.

API Documentation

See an example here: UWP samples on GitHub

robertos
  • 1,810
  • 10
  • 12
0

An System.OutOfMemoryException is usually raised on trying to read an image with System.Drawing that isn't actually one.

Checking up on my own Windows installation, it seems that those aren't the files you want to use for the user's profile picture (they were empty in my case).

I have found an already answered question which might help you instead: https://stackoverflow.com/a/9149243/7972419

Craftplacer
  • 100
  • 2
  • 8