Ejecta icon indicating copy to clipboard operation
Ejecta copied to clipboard

A example : Take a screenshot & Share the screenshot

Open finscn opened this issue 9 years ago • 40 comments

All code in index.js of this example:


//=======================================
// Initialize the screen canvas
//=======================================
var width = window.innerWidth;
var height = window.innerHeight;
var canvas = document.getElementById('canvas');
canvas.width = width;
canvas.height = height;
canvas.retinaResolutionEnabled = true;
var context = canvas.getContext("2d");
context.fillStyle = "#000000";
context.fillRect(0, 0, width, height);


//=======================================
// Draw something on screen canvas
//=======================================
context.fillStyle = "#ff6600";
context.font = "60px Arial";
context.fillText("Test", 30, 100);
context.fillRect(0, height >> 1, width, 20);
context.fillRect(width >> 1, 0, 20, height);


//=======================================
// Take a screenshot.
//=======================================
var appUtils = new Ejecta.AppUtils();
// In fact, saveImage() is a synchronous method.
// You could also use a offscreen canvas that you created via document.createElement().
appUtils.saveImage(canvas, "${Documents}/test.png", function(filePath) {
    console.log(filePath);
});


//=======================================
// Share the screenshot that you took.
//=======================================
var social = new Ejecta.Social();
// Why setTimeout :
// You can't open social dialog as soon as app starts
// You must wait a moment for initialization of SocialSDK
setTimeout(function() {
    social.showPostDialog('twitter', 'test message', "http://google.com", '${Documents}/test.png');
}, 1200);


finscn avatar Sep 07 '15 08:09 finscn

@matrixreal , I'v tried the best of my ability for helping you.

finscn avatar Sep 07 '15 08:09 finscn

@matrixreal , there is a full example https://github.com/phoboslab/Ejecta/issues/540

and Could you Star my fork version of Ejecta ?

finscn avatar Sep 07 '15 10:09 finscn

@matrixreal , you asked :

can i take screen shoot and save it on app folder ? not in the document? thanks i already stars your best fork :dancer:

Sorry , We can't do it . iOS does not allow us do that.

finscn avatar Sep 07 '15 12:09 finscn

@matrixreal , you can use ${Documents}, ${Library}, ${Caches}, ${tmp} . I think that's enough.

finscn avatar Sep 07 '15 12:09 finscn

social.showPostDialog seem not access to document folder the png file is there but when call the showpostdialog with that image not apear

matrixreal avatar Sep 07 '15 13:09 matrixreal

@matrixreal , Could you test https://github.com/phoboslab/Ejecta/issues/540 ? I am very sure that social.showPostDialog could access Documents folder .

finscn avatar Sep 07 '15 13:09 finscn

ok just copy what your link and paste it to index.js i got crash (ios7) crash

matrixreal avatar Sep 07 '15 13:09 matrixreal

@matrixreal , thanks . I don't have iOS 7.
Now update my fork version , I changed some codes.
Please Test again, thanks

finscn avatar Sep 07 '15 13:09 finscn

same error

matrixreal avatar Sep 07 '15 14:09 matrixreal

@matrixreal , thanks .

Please Update and test again .

finscn avatar Sep 07 '15 14:09 finscn

this could explain why showpostdialog can't access to documents ? no ? right ?

matrixreal avatar Sep 07 '15 14:09 matrixreal

No. Crash because the queue was lost.

finscn avatar Sep 07 '15 14:09 finscn

@matrixreal , Are there same errors ?

finscn avatar Sep 07 '15 14:09 finscn

same error but i see that you change something just now so i will download again and test

matrixreal avatar Sep 07 '15 14:09 matrixreal

can you pleas check again if showpostdialog can access to documents ?

matrixreal avatar Sep 07 '15 14:09 matrixreal

I am very sure that social.showPostDialog could access Documents folder .

finscn avatar Sep 07 '15 14:09 finscn

Now , I download iOS 7.1 SDK , and Test in simulator. That's OK. Please update and test again

finscn avatar Sep 07 '15 15:09 finscn

still same here ios 7.1.2 iphone 4s

matrixreal avatar Sep 07 '15 21:09 matrixreal

what's same? no image or crash ?

finscn avatar Sep 08 '15 00:09 finscn

@finscn now it work perfectly , some times crash but good better than nothing.... wow after 2 days of searching i could never done it without you thanks a lot ... if you want promote your app just write me

matrixreal avatar Sep 08 '15 00:09 matrixreal

@finscn last question when i use var context = canvas.getContext("2d"); (to make apputils saveimage work) i got screencanvas created 6 times ? do you have an idea ? sans titre

matrixreal avatar Sep 08 '15 00:09 matrixreal

"some times crash" in device or simulator ? or both ? Could you get the error message ?

"created 6 times " : I don't know , In my test case , there is no this problem .

finscn avatar Sep 08 '15 02:09 finscn

crash in device .... i don't use simulator since there are a lot of restrictions etc ... so i prefer real device ok i will post the log error as soon as it crash

matrixreal avatar Sep 08 '15 02:09 matrixreal

@finscn hahaaa now apputils is become good features than before

matrixreal avatar Sep 08 '15 02:09 matrixreal

@finscn is there a way to share an image like in showpostdialog but in openshare?

matrixreal avatar Sep 10 '15 13:09 matrixreal

~~No. the iOS API doesn't allow we do that.~~

finscn avatar Sep 11 '15 05:09 finscn

@finscn are you sure ? i have an app in my phone that share the snapshoot using openshare dialog

matrixreal avatar Sep 11 '15 08:09 matrixreal

@matrixreal , please update . now it could add image.

see

https://github.com/finscn/Ejecta/blob/master/App-Example/example/e-download-snapshot-share.js#L73

finscn avatar Sep 11 '15 11:09 finscn

works perfectly thanks

matrixreal avatar Sep 11 '15 16:09 matrixreal

hi,

i found that construct 2 (the tool i use to make html5 games) is using the line below to create canvas

var ctx = canvas.getContext("2d");

and the appUtils.saveImage call need the canvas initialize by var context = canvas.getContext("2d");

how can i modify it ? to use the ctx and not context ?

thanks

matrixreal avatar Oct 04 '15 14:10 matrixreal