Example output
WPF code
private void button5_Click(object sender, RoutedEventArgs e)
{
Image b = null;
int w = (int)this.Width;
int h = (int)this.Height;
System.Drawing.Size sz = new System.Drawing.Size((int)ActualWidth,
(int)ActualHeight);
System.Drawing.Point loc = new System.Drawing.Point((int)Left, (int)Top);
Hide();
System.Threading.Thread.Sleep(500);
using (b = new Bitmap(w, h))
{
using (Graphics g = Graphics.FromImage(b))
{
g.CopyFromScreen(loc, new System.Drawing.Point(0, 0), sz);
}
Image x = new Bitmap(b);
ImageBrush myBrush = new ImageBrush();
x.Save(@"C:\Users\Dell\Desktop\testImg.jpeg", ImageFormat.Jpeg);
myBrush.ImageSource = new BitmapImage(new Uri(@"C:\Users\Dell\Desktop\testImg.jpeg",
UriKind.Absolute));
this.Background = myBrush;
}
Show();
} This code will extract the image taking the current form size as Width and Height and grab its content using Bitmap class.

No comments:
Post a Comment