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. Ns3 构建哑铃型拓扑,并实现两个点的TCP连接(详细请戳全文)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaUAAADlCAIAAAB8n38hAAAV8UlEQVR4nO3dMWjjyBoH8CkNj1uc5v

  2. Beta吐槽

    目录 感想 管理团队 推进项目 pm吐槽 开发 经过我慎重的考虑,我jio得,Beta版本的吐槽还是不能少. 感想 管理团队 这学期十分庆幸成为我们这个这么优秀的团队的pm.身在pm的位置上经历这么一 ...

  3. iOS中block循环引用问题

    1.block是控制器对象的一个属性,则在block内部使用self将会引起循环应用 typedef void(^TestBlock)(); @interface SecondViewControll ...

  4. Beta阶段敏捷冲刺前准备

    一.介绍小组新加入的成员,Ta担任的角色. 新成员一:徐璐琳 风格:酷酷哒 擅长的技术:JAVA,CCNP 编程的兴趣:折磨人的快感 新角色:管理员 一句话宣言:打开开关又是一个机会 新成员二:祁泽文 ...

  5. Alpha冲刺——day3

    Alpha冲刺--day3 作业链接 Alpha冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602634 ...

  6. 【笔记】自学ST表笔记

    自学ST表笔记 说实话原先QBXT学的ST表忘的差不多了吧...... 我重新自学巩固一下(回忆一下) 顺便把原先一些思想来源的原博发上来 一.ST表简介 ST表,建表时间\(O(n\cdot log ...

  7. Optimal Milking POJ - 2112 (多重最优匹配+最小费用最大流+最大值最小化 + Floyd)

      Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 19347   Accepted: 690 ...

  8. 【USACO 1.4】Combination Lock

    /* TASK:combo LANG:C++ URL:http://train.usaco.org/usacoprob2?a=E6RZnAhV9zn&S=combo SOLVE:自己做,想的是 ...

  9. 【题解】 bzoj2435: [Noi2011]道路修建 (傻逼题)

    bzoj2435,懒得复制,戳我戳我 Solution: 模拟即可(有点傻逼啊 Code: //It is coded by Ning_Mew on 5.13 #include<bits/std ...

  10. 【BZOJ1228】[SDOI2009]E&D(博弈论)

    [BZOJ1228][SDOI2009]E&D(博弈论) 题面 BZOJ 洛谷 题解 这种打表找规律的题目真的不知道可以说什么好啊... #include<iostream> #i ...