Hi,
I’m making application CocosCreator which loading image from sdcard.
But, can not find solution or method.
I’ve tried to look around with jsb. But, it missed getFileData like c++.
Please, help !
Hi,
I’m making application CocosCreator which loading image from sdcard.
But, can not find solution or method.
I’ve tried to look around with jsb. But, it missed getFileData like c++.
Please, help !
Solution cocos2d-js :
In Java code :
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ............. //
saveInternalStorage();
loadInternalStorate();
}
public void saveInternalStorage()
{
Bitmap imageBitmap = BitmapFactory.decodeResource(sContext.getResources(), R.drawable.btn_star_big_on);
File file = new File(Cocos2dxHelper.getCocos2dxWritablePath() + "/" + "star.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
imageBitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e) {}
}
public void loadInternalStorate()
{
Bitmap imageBitmap = BitmapFactory.decodeFile(Cocos2dxHelper.getCocos2dxWritablePath() + "/" + "star.png");
System.out.println("imageBitmap : "+imageBitmap.getWidth()+" -- "+imageBitmap.getHeight());
}
In app.js
this.sprite = new cc.Sprite(jsb.fileUtils.getWritablePath()+"star.png");
this.sprite.attr({
x: size.width / 2,
y: size.height / 2
});
this.addChild(this.sprite, 0);
Solution Creator