CefSharp.OffScreen.Example
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的更多相关文章
- Winform下CefSharp的引用、配置、实例与报错排除(源码)
Winform下CefSharp的引用.配置.实例与报错排除 本文详细介绍了CefSharp在vs2013..net4.0环境下,创建Winfrom项目.引用CefSharp的方法,演示了winfro ...
- CefSharp的引用、配置、实例
CefSharp的引用.配置.实例与报错排除(源码) Winform下CefSharp的引用.配置.实例与报错排除 本文详细介绍了CefSharp在vs2013..net4.0环境下,创建Winfro ...
- CefSharp-基于C#的客户端开发框架技术栈开发全记录
CefSharp简介 源于Google官方 CefSharp用途 CefSharp开发示例 CefSharp应用--弹窗与右键 不弹出子窗体 禁用右键 CefSharp应用--High DPI问题 缩 ...
- 关于CefSharp的坎坷之路
项目背景: 公司的XX产品需要升级和以后支持多平台的使用.因为之前项目是由WPF实现的.目前以后想作为Html5来展示页面. 因为涉及到整体更改遇到的问题较多以及其他原因,所以只是内部内容区域先替换为 ...
- 解决 CefSharp WPF控件不能使用输入法输入中文的问题(代码已提交到 github)
首先,本文所有 代码已经提交到github,需要的可以直接从github获取:https://github.com/starts2000/CefSharp,希望可以帮助到有需要的朋友们. CEF 简介 ...
- 使用CefSharp开发一个12306“安心刷票弹窗通知”工具
有需求就要改进 最近两年没有在春节回家过年了,主要是票太难买,虽然之前写了一个12306“无声购票弹窗”工具,解决了抢票问题,但是全家老小一起回去还是很累,干脆就在北京过年了.这两天突然有一个朋友问我 ...
- cefsharp解决闪烁
CefSharp禁用GPU的命令行参数 其中,Major和Minor分别指代系统的主版本(大版本).次版本(小版本)版本号.其中指定了Windows7系统会禁用 GPU.,突发奇想,是否windows ...
- .net使用cefsharp开源库开发chrome浏览器(二)
离上篇写介绍pc端的混合开发和为什么以cefsharp入手研究混合开发已经有好几天,一直忙,抽不出时间继续写怎么搭建cefsharp开发环境.其实没有时间是借口,一切都是懒,没有爱到深处. 今天继续写 ...
- CefSharp初识--把网页移到桌面
在开发中我们可曾有过这样的需求,将某个网页嵌入到.Net应用中来,但Winform自带的web browser不怎么理想.CefSharp可以让我们在.Net应用中嵌入一个Chromium.它提供了W ...
随机推荐
- 第一个Sprint计划
时间:5月22-28日 (6天) 人员:杜殷浩(界面设计) 何广强(界面美化) 目标:将基本框架设计好,实现好.
- RYU 灭龙战 fourth day (2)
RYU 灭龙战 fourth day (2) 前言 之前试过在ODL调用他们的rest api,一直想自己写一个基于ODL的rest api,结果还是无果而终.这个小目标却在RYU身上实现了.今日说法 ...
- 团队作业4--第一次项目冲刺(Alpha版本)日志集合处
第一次 http://www.cnblogs.com/p-12/p/7861231.html 第二次 http://www.cnblogs.com/p-12/p/7861835.html 第三次 ht ...
- MongoDB ,cursor not found异常
查询mongoDB集合数据更新,数据有400w多.我一次用cursor(游标)取1w,处理更新.程序在某段时间运行中遍历游标时发生异常! DBCursor cursor = tabColl.find( ...
- Maven 学习笔记——将普通的Java项目转换成Maven项目(3)
将一个普通的java项目转换成Maven项目并不是一个很大的任务,仅仅只需要下面的几步就能将转换成功.下面我是用一个简单的Selenium测试小demon作为例子来说的. 移调项目中所有关联的Libr ...
- git如何删除已经 add 的文件 (如何撤销已放入缓存区文件的修改)
使用 git rm 命令即可,有两种选择, 一种是 git rm –cached “文件路径”,不删除物理文件,仅将该文件从缓存中删除: 一种是 git rm –f “文件路径”,不仅将该文件从缓存中 ...
- Docker(六)-Dcoker仓库
仓库 一个容易混淆的概念是注册服务器(Registry). 实际上注册服务器是管理仓库的具体服务器,每个服务器上可以有多个仓库,而每个仓库下面有多个镜像.从这方面来说, 仓库可以被认为是一个具体的项目 ...
- JavaWeb开发之详解Servlet及Servlet容器
自JavaEE诞生伊始,Servlet容器和Servlet技术,就构成了JavaEE应用的核心,配合其它组件,它们完善了Java企业级开发的全套解决方案.小到一个静态博客网站,大到分布式的集群应用,都 ...
- ES6之Promise用法详解
一 前言 本文主要对ES6的Promise进行一些入门级的介绍.要想学习一个知识点,肯定是从三个方面出发,what.why.how.下面就跟着我一步步学习吧~ 二 什么是Promise 首先是what ...
- Mac安装mysql8.0.12
···shell 下载 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12-macos10.13-x86_64.tar.gz ...