Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. [SOLVED] can I get an image from an embedded HTML5 Canvas into a QWidget?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] can I get an image from an embedded HTML5 Canvas into a QWidget?

Scheduled Pinned Locked Moved Qt WebKit
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pmh4514
    wrote on last edited by
    #1

    Hi

    I have a QWebView widget and the page which it loads contains an embedded HTML5 canvas element which shows a custom image/scene based on internet server data.

    On the Qt side (ie. within a slot on the main form) I'd like to "reach into" the DOM of the embedded webpage and "grab" the image data off the canvas element for further processing. I don't want the whole WebView, just the image data on the particular embedded canvas. Is this possible? If so, how?

    Thanks

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thebeast44
      wrote on last edited by
      #2

      using info from
      http://stackoverflow.com/questions/923885/capture-html-canvas-as-gif-jpg-png-pdf

      along with
      @
      QVariant QWebFrame::evaluateJavaScript ( const QString & scriptSource ) [slot]
      @

      you might be able to do something like

      @
      page()->mainFrame()->evaluateJavaScript("document.getElementsByTagName("canvas")[0].toDataURL("image/png")");
      @

      you'll have to change the script to suit your need

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pmh4514
        wrote on last edited by
        #3

        I got it to work by doing the following to copy the embedded canvas into a QImage, from there I can do with it what I need.

        @
        QWebElement el = myWebView->page()->mainFrame()->findFirstElement("#canvas0");

        QImage image(el.geometry().width(), el.geometry().height(), QImage::Format_ARGB32);
        QPainter painter(&image);
        el.render(&painter);
        painter.end();@
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved