I am trying to write a program. It will work at the background and it will constantly capture the screen, blur the image after that it will give me color of a pixel that I want. I tried to do this with that code. But it give me pixel color without blur effect. How can I get the blurry pixel color?
Screenshot, blur and get pixel function:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Hide();
Bitmap foto = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();
System.Threading.Thread.Sleep(200);
Graphics grafik = Graphics.FromImage(foto);
grafik.CopyFromScreen(0, 0, 0, 0, new System.Drawing.Size(foto.Width, foto.Height));
imgBox.Source = BitmapToImageSource(foto);
myBlurEffect.Radius = myBlurValue;
imgBox.BitmapEffect = myBlurEffect;
colorValue.Text = foto.GetPixel(foto.Width / 2, foto.Height / 2).ToString();
this.Show();
}
XAML file:
<Image Name="imgBox" HorizontalAlignment="Left" Height="419" VerticalAlignment="Top" Width="792" ></Image>
<Button Content="Take ScreenShot" HorizontalAlignment="Left" Margin="674,389,0,0" VerticalAlignment="Top" Width="108" Cursor="Hand" Click="Button_Click"/>
<Button Name="blurDown" Content="-" HorizontalAlignment="Left" Margin="10,394,0,0" VerticalAlignment="Top" Width="75" Cursor="Hand" Click="Button_Click_Down"/>
<Button Name="blurUp" Content="+" HorizontalAlignment="Left" Margin="90,394,0,0" VerticalAlignment="Top" Width="75" Cursor="Hand" Click="Button_Click_Up"/>
<TextBox Name="blurValue" HorizontalAlignment="Center" Height="23" Margin="338,386,334,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" TextAlignment="Center" FontWeight="Bold" Background="{x:Null}" Foreground="White" BorderBrush="{x:Null}">
<TextBox.Effect>
<DropShadowEffect/>
</TextBox.Effect>
</TextBox>
<TextBox Name="colorValue" HorizontalAlignment="Center" Height="23" Margin="261,10,257,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="274" TextAlignment="Center" FontWeight="Bold" Background="{x:Null}" Foreground="White" BorderBrush="{x:Null}">
<TextBox.Effect>
<DropShadowEffect/>
</TextBox.Effect>
</TextBox>