Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

Screenshot save dialog

GameMaker & Construct 2 plugins to let user pick where to save screenshot(s). · By YellowAfterlife

Save specific surface?

A topic by twistoon created Jul 29, 2020 Views: 97 Replies: 7
Viewing posts 1 to 3

Hi, is there a way that we can save a specific surface with this rather than just the screen in html5 please? :) Thank you 

Developer

This extension uses a trick involving drawing the GM canvas onto another canvas to get base64 of it, but surfaces are not canvases on WebGL.

I think your best bet would be to grab pixels using buffer_get_surface, then grab a raw buffer object (Uint8Array I think? Or maybe ArrayBuffer) using buffer_get_address, then convert those pixels into ImageData, then putImageData it onto canvas, and then you can finally get base64 of it and use the rest of the existing code.

(2 edits)

Hi, Thank you so much for answering, sorry I wasn't clear that I was using Gamemaker... I see that I can go up to the buffer_get_address in gamemaker, but can't see ImageData or putimagedata... so I'd have to make an extension from there in JS for it to work? :) 

Developer

Correct - either make an extension or edit this same one (since it has some of the code anyway)

Thankyou :) I'll give it a go, I hadn't seen that the code was with the extension.

Hey, this extension is great. However I am just wondering if the surface can be saved without user dialogue? I mean to save a surface to a file which can be loaded later, without asking user to provide/select the filename? (I am using GM and looking for a solution for HTML5).

Developer(+1)

If you want to save the surface "somewhere" but not necessarily in a user-accessible location, you could use buffer_get_surface and then buffer_base64_encode to convert it to a string you could save (or, perhaps, buffer_save will also work).

Thanks for your reply. I tried some way, maybe the problem is at my end, but could not get it work.

Surface_save works well on windows.exe (but not with html5), however  buffer_get_surface+buffer_save or buffer_get_surface+buffer_base64_encode+file_text_write_string did not work at all. 

Anyway, thank you.