15 Eylül 2014 Pazartesi

c# ile ekran görüntüsü almak için gereken kodlar

c# ile ekran görüntüsü almak kaynak kodlar

private Bitmap Screenshot()
{
    //Create a bitmap with the same dimensions like the screen
    Bitmap screen = new Bitmap(SystemInformation.VirtualScreen.Width,
                                         SystemInformation.VirtualScreen.Height);
 
    //Create graphics object from bitmap
    Graphics g = Graphics.FromImage(screen);
 
    //Paint the screen on the bitmap
    g.CopyFromScreen(SystemInformation.VirtualScreen.X,
                             SystemInformation.VirtualScreen.Y,
                             0, 0, screen.Size);
    g.Dispose();
 
    //return bitmap object / screenshot
    return screen;
}

c# website görüntüsünü alma

c# ile screenshot alma website görüntüsü almak için kodlar

private void WebsiteScreenshot(string url, string file)
{
    //Create a webbrwoser object
    WebBrowser browser = new WebBrowser();
 
    //Deactivate scrollbars, unless you want them to
    //appear on your screenshot
    browser.ScrollBarsEnabled = false;
 
    //Suppress (java-)script error popups
    browser.ScriptErrorsSuppressed = true;
 
    //Open the given url in webbrowser
    browser.Navigate(new Uri(url));
 
    //Wait until the page is fully loaded
    while (browser.Document == null || browser.Document.Body == null)
           Application.DoEvents();
 
     //Resize the webbrowser object to the same size as the
     //webpage
     Rectangle websiteSize = browser.Document.Body.ScrollRectangle;
     browser.Size = new Size(websiteSize.Width,websiteSize.Height);
 
     //Create a bitmap object with the same dimensions as the website
     Bitmap bmp = new Bitmap(websiteSize.Width, websiteSize.Height);
 
     //Paint the website contents to the bitmap
     browser.DrawToBitmap(bmp,
          new Rectangle(0, 0, websiteSize.Width, websiteSize.Height));
 
     browser.Dispose();
 
     //Save the bitmap at the given filepath
     bmp.Save(file, ImageFormat.Png);
}
You can then call the method as follows:
1
2
3
//If you want file extension than .png, don't forget to change the
//ImageFormat-type in the above main function!
WebsiteScreenshot("http://en.code-bude.net/", "c:\website_screenshot.png");