NWjs - Write File in ".png"

Get help using Construct 2

Post » Tue Feb 07, 2017 10:33 pm

I need to save as PNG-file my CanvasSnapshot.
"Brower.InvodeDownload" can do it, but "NWjs.WriteFile" creates the unreadable file in PNG-format.

Is there any way to do it?
B
53
S
26
G
57
Posts: 141
Reputation: 33,020

Post » Tue Feb 07, 2017 11:25 pm

InvokeDownload works perfect and can save *png.
Why would you need to use anything else?
I'm a Magician, not a Developer.
B
27
S
9
G
25
Posts: 126
Reputation: 14,623

Post » Tue Feb 07, 2017 11:25 pm

To cut a long story short I have found the solution by myself.
We should use "tokenat(CanvasSnapshot,1,",")" instead of just "CansavSnapshot".
Also we should find "writefile" function in "c2runtime.js", go 5 steps down and change "UTF8" with "Base64"
B
53
S
26
G
57
Posts: 141
Reputation: 33,020

Post » Tue Feb 07, 2017 11:30 pm

XpMonster wrote:InvokeDownload works perfect and can save *png.
Why would you need to use anything else?

Because I am creating a program like "Spriter" and I do not want user to click LMB every time my program saves the image.
B
53
S
26
G
57
Posts: 141
Reputation: 33,020

Post » Tue Feb 07, 2017 11:39 pm

Well if your program will be more like thing we had in Construct Classic I would be more than glad to purchase it! Best of luck.
I'm a Magician, not a Developer.
B
27
S
9
G
25
Posts: 126
Reputation: 14,623

Post » Wed Feb 08, 2017 12:01 am

XpMonster wrote:Well if your program will be more like thing we had in Construct Classic I would be more than glad to purchase it! Best of luck.

Thank you. I will try my best.
B
53
S
26
G
57
Posts: 141
Reputation: 33,020

Post » Fri Aug 18, 2017 10:26 pm

paradine wrote:To cut a long story short I have found the solution by myself.
We should use "tokenat(CanvasSnapshot,1,",")" instead of just "CansavSnapshot".
Also we should find "writefile" function in "c2runtime.js", go 5 steps down and change "UTF8" with "Base64"


Hi,

Do you happen to have an example available? i am trying to do the same thing. I would like to download an image without giving the user a pop up.

Thanks,
B
40
S
11
G
1
Posts: 212
Reputation: 4,545

Post » Sat Aug 19, 2017 6:03 am

Nw.js write image file

MadSpy wrote:For screenshot:

Code: Select all
Browser.ExecJS("var fs = require('fs');fs['writeFileSync']('" &replace(NodeWebkit.UserFolder & "screenshot" & ".png","\","\\")& "','" &CanvasSnapshot& "'.split(',')[1], {'encoding': 'base64'});")



nwjsWriteScreenshot.capx
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,084


Return to How do I....?

Who is online

Users browsing this forum: Exion, Yahoo [Bot] and 6 guests