Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JS magic: asking browser to save (image) content of a HTML canvas?

    I have a widget which uses a HTML Canvas tag to hold some drawing, which is drawn by some JS library.

    If I right-click on the image, the browser offers the same context menu which is used with normal images: among other things, it offers the possibility to "save image as..."

    My question is, can I achieve this from code?

    How can I ask the browser the save content of the canvas?

    Obviously I can not access the filesystem, but I do not need that: I just want to show the download dialog, which would be shown if the user has chosen "save image as" from the content menu.

    Is this possible?

    Thank you for your help:

    #2
    No way to know without knowing how this other JS library is drawing an image (loaded from server? "data:" URL?)

    Comment


      #3
      It's not loading from server, and when I right-click on the image and select "view image", I get a data url.

      Comment


        #4
        If some other library is generating "data:" URLs, use low-level browser DOM APIs to get to it, send it to the server, and decode it into a normal image data there.

        This is not a SmartGWT question but that's the general approach.

        Comment

        Working...
        X