For an app, I have to load and manipulate images that are taken by the camera.
On my phone they're stored in /media/sdcard/DCIM/Camera. How do I load those
images? If I try
CCSprite foo = CCSprite.sprite("/path/to/image");
it tries to load from the assets directory.
A coworker hacked together this solution to nodes/CCSprite.java:
public static CCSprite sprite(String filepath) {
return new CCSprite(filepath, 0);
}
public static CCSprite spriteExternal(String filepath) {
return new CCSprite(filepath, 1);
}
[...]
public CCSprite(String filename,int pathType) {
assert filename!=null:"Invalid filename for sprite";
CCTexture2D texture;
if (pathType==1)
texture = CCTextureCache.sharedTextureCache().addImageExternal(filename);
else
texture = CCTextureCache.sharedTextureCache().addImage(filename);
if( texture != null) {
CGRect rect = CGRect.make(0, 0, 0, 0);
rect.size = texture.getContentSize();
init(texture, rect);
} else {
ccMacros.CCLOGERROR("CCSprite", "Unable to load texture from file: " + filename);
}
}
For men backgrounds, he also added this tiny function to
menus/CCMenuItemImage.java:
public static CCMenuItemImage itemExternal(String value, String value2, CCNode t, String sel) {
return new CCMenuItemImage(CCSprite.spriteExternal(value), CCSprite.spriteExternal(value2), null , t, sel);
}
Is there a better (builtin) method to do this sort of thing? Perhaps we've
missed something.
(If not, please consider adding something similar to the code base.)
Original issue reported on code.google.com by far...@gmail.com on 29 Jun 2011 at 3:03
Original issue reported on code.google.com by
far...@gmail.com
on 29 Jun 2011 at 3:03