How to take screenshot by CEF?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How to take screenshot by CEF?

Postby milaneuo » Sun Apr 30, 2017 12:49 am

Hi all:
How to take screenshot of the webpage by CEF c++.
Thanks very much.
milaneuo
Newbie
 
Posts: 1
Joined: Sun Apr 30, 2017 12:46 am

Re: How to take screenshot by CEF?

Postby Czarek » Sun Apr 30, 2017 12:24 pm

In windowed mode you can render window contents to a bitmap using native APIs.
In off-screen-rendering mode implement CefRenderHandler and at least two of its callbacks: GetViewRect and OnPaint.

If you don't mind using Python then there is a simple example "screenshot.py" in CEF Python. It uses off-screen rendering mode. This code could also act as a reference in writing C++ equivalent code. See: https://github.com/cztomczak/cefpython/ ... eenshot.py
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How to take screenshot by CEF?

Postby Czarek » Mon May 01, 2017 10:58 pm

Chrome v59 now supports headless mode which has some interesting flags. Running with --screenshot will produce a file named screenshot.png in the current working directory:

Code: Select all
chrome --headless --screenshot https://www.chromestatus.com/

# Size of a standard letterhead.
chrome --headless --screenshot --window-size=1280,1696 https://www.chromestatus.com/

# Nexus 5x
chrome --headless --screenshot --window-size=412,732 https://www.chromestatus.com/


I don't think CEF supports the --screenshot flag though.

Ref: https://developers.google.com/web/updat ... ess-chrome
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am


Return to CEF Discussion

Who is online

Users browsing this forum: Google [Bot] and 26 guests