namespace CefSharp.OffScreen.Example
{
public class Program
{
private static ChromiumWebBrowser browser; public static void Main(string[] args)
{
const string testUrl = "http://www.baidu.com/"; Console.WriteLine("This example application will load {0}, take a screenshot, and save it to your desktop.", testUrl);
Console.WriteLine("You may see a lot of Chromium debugging output, please wait...");
Console.WriteLine(); // You need to replace this with your own call to Cef.Initialize();
CefExample.Init(); // Create the offscreen Chromium browser.
browser = new ChromiumWebBrowser(); // An event that is fired when the first page is finished loading.
// This returns to us from another thread.
browser.FrameLoadEnd += BrowserFrameLoadEnd; // Start loading the test URL in Chrome's thread.
//browser.Load(testUrl);
browser.Load("dummy:"); // We have to wait for something, otherwise the process will exit too soon.
Console.ReadKey(); // Clean up Chromium objects. You need to call this in your application otherwise
// you will get a crash when closing.
Cef.Shutdown();
} private static void BrowserFrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
ChromiumWebBrowser browser = sender as ChromiumWebBrowser;
if (browser.Title == "dummy:")
{
browser.LoadHtml("<html><head></head><body><h1>OKOKOK</h1></body></html>", "about:blank");
return;
} // Check to ensure it is the main frame which has finished loading
// (rather than an iframe within the main frame).
if (e.IsMainFrame)
{
// Remove the load event handler, because we only want one snapshot of the initial page.
browser.FrameLoadEnd -= BrowserFrameLoadEnd; var task1 = browser.GetSourceAsync();
task1.Wait();
string html= task1.Result; // Wait for the screenshot to be taken.
var task = browser.ScreenshotAsync();
task.Wait(); // Make a file to save it to (e.g. C:\Users\jan\Desktop\CefSharp screenshot.png)
var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png"); Console.WriteLine();
Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath); // Save the Bitmap to the path.
// The image type is auto-detected via the ".png" extension.
task.Result.Save(screenshotPath); // We no longer need the Bitmap.
// Dispose it to avoid keeping the memory alive. Especially important in 32-bit applications.
task.Result.Dispose(); Console.WriteLine("Screenshot saved. Launching your default image viewer..."); // Tell Windows to launch the saved image.
Process.Start(screenshotPath); Console.WriteLine("Image viewer launched. Press any key to exit.");
}
}
}
}

  

CefSharp.OffScreen.Example的更多相关文章

  1. Winform下CefSharp的引用、配置、实例与报错排除(源码)

    Winform下CefSharp的引用.配置.实例与报错排除 本文详细介绍了CefSharp在vs2013..net4.0环境下,创建Winfrom项目.引用CefSharp的方法,演示了winfro ...

  2. CefSharp的引用、配置、实例

    CefSharp的引用.配置.实例与报错排除(源码) Winform下CefSharp的引用.配置.实例与报错排除 本文详细介绍了CefSharp在vs2013..net4.0环境下,创建Winfro ...

  3. CefSharp-基于C#的客户端开发框架技术栈开发全记录

    CefSharp简介 源于Google官方 CefSharp用途 CefSharp开发示例 CefSharp应用--弹窗与右键 不弹出子窗体 禁用右键 CefSharp应用--High DPI问题 缩 ...

  4. 关于CefSharp的坎坷之路

    项目背景: 公司的XX产品需要升级和以后支持多平台的使用.因为之前项目是由WPF实现的.目前以后想作为Html5来展示页面. 因为涉及到整体更改遇到的问题较多以及其他原因,所以只是内部内容区域先替换为 ...

  5. 解决 CefSharp WPF控件不能使用输入法输入中文的问题(代码已提交到 github)

    首先,本文所有 代码已经提交到github,需要的可以直接从github获取:https://github.com/starts2000/CefSharp,希望可以帮助到有需要的朋友们. CEF 简介 ...

  6. 使用CefSharp开发一个12306“安心刷票弹窗通知”工具

    有需求就要改进 最近两年没有在春节回家过年了,主要是票太难买,虽然之前写了一个12306“无声购票弹窗”工具,解决了抢票问题,但是全家老小一起回去还是很累,干脆就在北京过年了.这两天突然有一个朋友问我 ...

  7. cefsharp解决闪烁

    CefSharp禁用GPU的命令行参数 其中,Major和Minor分别指代系统的主版本(大版本).次版本(小版本)版本号.其中指定了Windows7系统会禁用 GPU.,突发奇想,是否windows ...

  8. .net使用cefsharp开源库开发chrome浏览器(二)

    离上篇写介绍pc端的混合开发和为什么以cefsharp入手研究混合开发已经有好几天,一直忙,抽不出时间继续写怎么搭建cefsharp开发环境.其实没有时间是借口,一切都是懒,没有爱到深处. 今天继续写 ...

  9. CefSharp初识--把网页移到桌面

    在开发中我们可曾有过这样的需求,将某个网页嵌入到.Net应用中来,但Winform自带的web browser不怎么理想.CefSharp可以让我们在.Net应用中嵌入一个Chromium.它提供了W ...

随机推荐

  1. 四则运算level2

    package j; import java.util.Scanner; public class Main { public static void main(String[] args) { Sc ...

  2. TAC队--团队选题报告

    The Art of Code--团队选题报告 一个APP项目能否被大众所接受,能否拥有受众,the most important是它的idea. 一个好的idea可以为项目带来巨大的改变 一个 独特 ...

  3. 小程序 JM

    // 本地 // 'https://ly.com/' // 短信验证码参数: let dataValue = { 'type': 1, mobile: '13615814562' }; dataVal ...

  4. 2013长春网赛1009 hdu 4767 Bell(矩阵快速幂+中国剩余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4767 题意:求集合{1, 2, 3, ..., n}有多少种划分情况bell[n],最后结果bell[ ...

  5. Java微信二次开发(一)

    准备用Java做一个微信二次开发项目,把流程写在这里吧. 第一天,做微信请求验证 需要导入库:servlet-api.jar 第一步:新建包com.wtz.service,新建类LoginServle ...

  6. C# 登录窗口的设计技巧

    记得很久之前要用C#做个需要登录的小东西,自己之前完全没有编写WinForm的经验,整个过程中,自己感觉应该怎么写就怎么写,时常导致许多逻辑性的错误,比如在做这个登录窗口的时候,应该实现的效果是,用户 ...

  7. 一本通1641【例 1】矩阵 A×B

    1641: [例 1]矩阵 A×B sol:矩阵乘法模板.三个for循环 #include <bits/stdc++.h> using namespace std; typedef lon ...

  8. Codeforces Round #528 Div. 1 自闭记

    整天自闭. A:有各种讨论方式.我按横坐标排了下然后讨论了下纵坐标单调和不单调两种情况.写了15min也就算了,谁能告诉我printf和cout输出不一样是咋回事啊?又调了10min啊?upd:突然想 ...

  9. hdwiki 前后台版权信息在哪修改

    hdwiki 前台copyright 信息在 view/default/footer.htm 搜索footer-phdwiki 后台copyright 信息在 view/default/admin_m ...

  10. Java Socket/HttpURLConnection读取HTTP网页

    以读取百度的http网页为例.如果知道了IP地址和端口,然后新建一个Socket,就直接去读百度的首页,根本没反应,原因是www.baidu.com是以http协议传输的,而现在要以Socket原始的 ...