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 ?