How do I export/import an image to and from clipboard?

0 favourites
  • 9 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. Suitable for casual games
  • I'm thinking the binary object plus AJAX might be the way to go?

    It doesn't need to be fast. I want to copy a sprite to and from photoshop

  • This works on chrome 84 to load an image from the clipboard. Not sure if other browsers do it differently. It was a bit different than the mozilla documentation about the clipboard api.

    Writing to the clipboard is possible too but I had nothing to write.

    dropbox.com/s/yeoltfvz63hpasb/js_read_image_from_clipboard.capx

    For c3 I think you may need to change c2_callFunction to c3_callFunction, unless something else changed with new functions.

  • Thank you so much R0J0hound You were already in the credits...

    This worked right out of the box ( C3 lets you type js anywhere, not just the browser object, but it's the same)

    I understand some of this, there's somePromises, and then you call a blob constructor.

    Do you know how you would write the contents of the Canvas to the clipboard?

    There's a clipboard.write but I'm not sure how

    Thanks again

  • Updated the example to write an image url to the clipboard.

    Internally it creates an image and a canvas, loads the imageUrl into the image, draws it to the canvas, gets a blob from the canvas, and sets the clipboard from that.

  • this one doesn't work in C3's javascript, and I don't understand it, but it still works great in the browser object.

    Thanks so much <3

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound would you happen to know how to get the img.src to contain the image data from a sprite?

    EDIT: Ah I thought for a minute and solved it:

    1. paste the sprite to Canvas

    2. on canvas screenshot set img.src ='"&drawingCanvas.savedImageURL&"'

    thanks a million for all the help rojo

  • wow, a BIG thanks to both of you! I have been working all week on adding a javascript function that can resize very large images without loosing too much detail. I was jumping through all kinds of hoops using binary data and AJAX. This cuts out a lot of steps. So thanks again.

    the sample code below adds the img to the document so that I could see that it actually made it to the script. In my project I will be passing it over to the resizing function which will be pasting it back to the Drawing Canvas... Another "quirt" of Construct 3 that held me up is that when you resize a Drawing Canvas you must wait until its "On resolution changed" trigger fires and then draw something (anything) into it to make the resize complete. My script kept complaining that the Drawing Canvas was the wrong size and would not load the the resized image.

  • Glad it worked and was helpful.

    -cheers

  • I was wondering AllanR why r0j0's code for pasting to clipboard doesn't work in native C3 javascript, but only in browser> execute javascript

    My guess is something isn't implemented, but what? Can you make it work outside the browser object?

    EDIT: Ah I figured I'd use your solution with a global string,

    1| set imgURL to DrawingCanvas.SavedImageURL

    2| img.src = runtime.globalVars.imgURL

    to get the contents of the image, and it worked like a charm <3

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)