Now the resolver looks like this:
1, using the JNI transfer Java method to start the album selection box
2. Images from Java will be saved to the local
3, using Cocos2d-x in Ccimage reading
The Java code is as follows:
Start Picture selection box
private void Launchcamera ()
{
TODO auto-generated Method Stub
Intent Intent = new Intent ();
Intent.settype ("image/*");//set Intent Type
Intent.setaction (intent.action_get_content);
Get picture information back to Mainactivity
Startactivityforresult (intent,1);
}
Picture Selection Callback
protected void Onactivityresult (int requestcode,int resultcode,intent data)
{
if (RESULTCODE==RESULT_OK)
{
Uri uri = Data.getdata ();
Get image absolute address by URI
String[] proj = {MediaStore.Images.Media.DATA};
cursor cursor = managedquery (uri,proj,null,null,null);
int actual_image_column_index = Cursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA);
Cursor jumps to the first place to prevent cross-border
Cursor.movetofirst ();
String Img_path = cursor.getstring (Actual_image_column_index);
Get bitmap information by address
Bitmap Bitmap =bitmapfactory.decodefile (Img_path);
Savemybitmap ("001", bitmap);
}
}
Save picture to Local
private void Savemybitmap (String bitname,bitmap mbitmap)
{
File F = new file ("/sdcard/" + Bitname + ". png");
try {
F.createnewfile ();
} catch (IOException e) {
TODO auto-generated Catch block
}
FileOutputStream fOut = null;
try {
FOut = new FileOutputStream (f);
} catch (FileNotFoundException e) {
E.printstacktrace ();
}
Mbitmap.compress (Bitmap.CompressFormat.PNG, FOut);
try {
Fout.flush ();
} catch (IOException e) {
E.printstacktrace ();
}
try {
Fout.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
C + + code such as the following:
Read locally stored data
ccsprite* Loadinglayer::loadimage ()
{
ccsprite* tempsprite = NULL;
Const char* Path = "/sdcard/001.png";
file* fp = fopen (path, "RB");
if (!FP)
{
return tempsprite;
}
Fseek (Fp,0,seek_end);
int len = ftell (FP);
Fseek (Fp,0,seek_set);
char* buf = (char*) malloc (len);
Fread (BUF,LEN,1,FP);
Fclose (FP);
if (len==0 | | buf==null)
{
return tempsprite;
}
ccimage* img = new Ccimage;
Img->initwithimagedata (Buf,len);
Free (BUF);
cocos2d::cctexture2d* texture = new cocos2d::cctexture2d ();
Texture->initwithimage (IMG);
Img->release ();
Tempsprite = ccsprite::createwithtexture (texture);
Texture->release ();
return tempsprite;
}
Android Cocos2d-x flipping through album data