public async Task ChangeColor()
{
try
{
await Dispatcher.BeginInvoke((Action) (() =>
{
Thread thread = new Thread(new ThreadStart(delegate ()
{
System.Threading.Thread.Sleep(200);
this.Dispatcher.BeginInvoke(DispatcherPriority.Send,
new ThreadStart(async delegate ()
{
var topLeftCorner = WebView.PointToScreen(new System.Windows.Point(0, 0));
var topLeftGdiPoint = new System.Drawing.Point((int)topLeftCorner.X, (int)topLeftCorner.Y);
var size = new System.Drawing.Size((int)WebView.ActualWidth, (int)WebView.ActualHeight);
Bitmap screenShot = new Bitmap((int)WebView.ActualWidth, (int)WebView.ActualHeight);
using (var graphics = Graphics.FromImage(screenShot))
{
graphics.CopyFromScreen(topLeftGdiPoint, new System.Drawing.Point(), size,
CopyPixelOperation.SourceCopy);
}
SolidColorBrush oldBrush = (SolidColorBrush)Panel.Background;
SolidColorBrush brush = new SolidColorBrush(StaticFunctions.ToMediaColor(screenShot.GetPixel(1, 1)));
StaticFunctions.AnimateColor(oldBrush, StaticFunctions.ToMediaColor(screenShot.GetPixel(1, 1)), Panel, 0.1);
mainWindow.TabBar.getTabFromForm(this).Color = brush;
mainWindow.TabBar.getTabFromForm(this).refreshColor();
StaticFunctions.AnimateColor(oldBrush, StaticFunctions.ToMediaColor(screenShot.GetPixel(1, 1)), textBox, 0.1);
StaticFunctions.AnimateColor(oldBrush, StaticFunctions.ToMediaColor(screenShot.GetPixel(1, 1)), ListContainer, 0.1);
StaticFunctions.AnimateColor(oldBrush, StaticFunctions.ToMediaColor(screenShot.GetPixel(1, 1)), MagicBox, 0.1);
await ContrastColor(screenShot.GetPixel(1, 1));
this.Refresh();
}));
}));
thread.Name = "thread-UpdateText";
thread.Start();
}));
}
catch (Exception ex)
{
Console.WriteLine("Change color error: " + ex.Message + " " + ex.Data);
}
}