Exemple #1
0
        public static Color GetColorFromImage(string sourceImagePath)
        {
            var outputColor  = Color.Gray;
            var sourceBitmap = new Bitmap(1, 1);

            if (sourceImagePath == Environment.ExpandEnvironmentVariables(@"%windir%\Explorer.exe"))
            {
                outputColor = Color.FromArgb(255, 0, 130, 153);
            }
            else if (File.Exists(sourceImagePath) || Directory.Exists(sourceImagePath))
            {
                if (File.Exists(sourceImagePath))
                {
                    sourceBitmap = Bitmap.FromHicon(Icon.ExtractAssociatedIcon(sourceImagePath).Handle);
                }
                else if (Directory.Exists(sourceImagePath))
                {
                    var shinfo = new WinApi.ShFileInfo();
                    WinApi.SHGetFileInfo(sourceImagePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), 256);
                    sourceBitmap = Bitmap.FromHicon(shinfo.hIcon);
                }

                Color destColor;
                using (var destBitmap = new Bitmap(1, 1))
                    using (var g = Graphics.FromImage(destBitmap))
                    {
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.DrawImage(sourceBitmap, 0, 0, 1, 1);

                        destColor = destBitmap.GetPixel(0, 0);
                    }
                outputColor = Color.FromArgb(255, destColor.R, destColor.G, destColor.B);
            }

            return(outputColor);
        }
Exemple #2
0
 public static void RestartSystem()
 {
     WinApi.ExitWindowsEx(WinApi.ExitWindowsAction.Reboot, 0);
 }
Exemple #3
0
 public static void ShutDownSystem()
 {
     WinApi.ExitWindowsEx(WinApi.ExitWindowsAction.Shutdown, 0);
 }
Exemple #4
0
 public static void SleepSystem()
 {
     WinApi.SetSuspendState(false, true, true);
 }
Exemple #5
0
 public static void SignOut()
 {
     WinApi.ExitWindowsEx(WinApi.ExitWindowsAction.Force, 0);
 }
Exemple #6
0
 public static void LockUserAccount()
 {
     WinApi.LockWorkStation();
 }