Код: Выделить всё
#include
#include
void on_snapshot_finished(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
WebKitWebView *web_view = WEBKIT_WEB_VIEW(source_object);
cairo_surface_t *surface = webkit_web_view_get_snapshot_finish(web_view, res, NULL);
if (surface)
{
g_print("found surface.\n");
cairo_surface_write_to_png(surface, "output.png");
}
else
{
g_print("no surface.\n");
}
gtk_main_quit();
}
static void load_changed(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer user_data)
{
if (load_event == WEBKIT_LOAD_FINISHED)
{
webkit_web_view_get_snapshot(web_view, WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND, NULL, on_snapshot_finished, NULL);
}
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window = gtk_offscreen_window_new();
gtk_window_set_default_size(GTK_WINDOW(window), 1280, 720);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
WebKitWebView *web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
g_signal_connect(web_view, "load-changed", G_CALLBACK(load_changed), NULL);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(web_view));
webkit_web_view_load_uri(web_view, "https://www.google.com"/);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... nd-webkit2