Home > other >  Converting .dat File to Image File in C#
Converting .dat File to Image File in C#

Time:12-21

im trying to get windows user profile pictur 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 im 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 var

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

CodePudding user response:

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

CodePudding user response:

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

  • Related