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
52
S
24
G
46
Posts: 132
Reputation: 27,279

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
22
S
8
G
25
Posts: 106
Reputation: 14,294

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
52
S
24
G
46
Posts: 132
Reputation: 27,279

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
52
S
24
G
46
Posts: 132
Reputation: 27,279

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
22
S
8
G
25
Posts: 106
Reputation: 14,294

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
52
S
24
G
46
Posts: 132
Reputation: 27,279

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
38
S
11
G
1
Posts: 203
Reputation: 4,473

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,518
Reputation: 11,072


Return to How do I....?

Who is online

Users browsing this forum: jogindarpradeep and 18 guests