finscn / Ejecta

A Fast, Open Source JavaScript, Canvas & Audio Implementation for iOS
42 stars 6 forks source link

A example : Take a screenshot & Share the screenshot #23

Open finscn opened 9 years ago

finscn commented 9 years ago

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 commented 9 years ago

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

finscn commented 9 years ago

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

and Could you Star my fork version of Ejecta ?

finscn commented 9 years ago

@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 commented 9 years ago

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

matrixreal commented 9 years ago

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

finscn commented 9 years ago

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

matrixreal commented 9 years ago

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

finscn commented 9 years ago

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

matrixreal commented 9 years ago

same error

finscn commented 9 years ago

@matrixreal , thanks .

Please Update and test again .

matrixreal commented 9 years ago

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

finscn commented 9 years ago

No. Crash because the queue was lost.

finscn commented 9 years ago

@matrixreal , Are there same errors ?

matrixreal commented 9 years ago

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

matrixreal commented 9 years ago

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

finscn commented 9 years ago

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

finscn commented 9 years ago

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

matrixreal commented 9 years ago

still same here ios 7.1.2 iphone 4s

finscn commented 9 years ago

what's same? no image or crash ?

matrixreal commented 9 years ago

@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 commented 9 years ago

@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

finscn commented 9 years ago

"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 .

matrixreal commented 9 years ago

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 commented 9 years ago

@finscn hahaaa now apputils is become good features than before

matrixreal commented 9 years ago

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

finscn commented 9 years ago

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

matrixreal commented 9 years ago

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

finscn commented 9 years ago

@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

matrixreal commented 9 years ago

works perfectly thanks

matrixreal commented 9 years ago

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 commented 9 years ago

@finscn i think i found it this is working saveImage is only working with canvas 2d and not canvas webgl i think it need update

finscn commented 9 years ago

1) "ctx" or "context" is not the point. you can use any name of variables . 2) It supports WebGL .

matrixreal commented 9 years ago

yes yes thats okay ... but for sure the saveimage call is not working on webgl mode

finscn commented 9 years ago

saveImage supports WebGL . I test it in pure WebGL , not construct 2 . Maybe the problem is about something else ,not 2D or WebGL

finscn commented 9 years ago

Sorry , I make a mistake. I've not tested it with WebGL. I will try it later.

matrixreal commented 9 years ago

:D* you are welcome ....

matrixreal commented 9 years ago

@finscn hi any news ? about the webgl

matrixreal commented 8 years ago

@finscn any news please ?

finscn commented 8 years ago

@matrixreal , Sorry , My macbook is breakdown (in fixing). Now I work on a windows PC . So I don't do anything about Ejecta . My macbook will be back in Next week

finscn commented 8 years ago

@matrixreal , update and try again