Can't see any .so file in my jnilibs

Yes,

I have a cocos2d-x game running on android. & I want to take a screenshot of the game and save it to your Android Device Gallery …

Try this method:

cocos2d::utils::captureScreen();

1 Like

Yup or I was also thinking RenderTexture depending upon needs. You answer to take a quick snap is probably best.

@R101 How can i pass captured image to android ?
cocos2d::utils::captureScreen(); could you define both methods for ios & android which capture screenshot ?

Open up the ccUtils.h file where cocos2d::utils::captureScreen() is defined, and read the comments above the function. Also, look at the signature of the function. The answer is there. When it takes the screenshot, it gets saved out to the writable path, and that path is given back to you in a callback. What you choose to do with it after that is up to you.

As for iOS and Android, again, if you would simply open up that ccUtils.h file, you would quickly realise that it’s not specific to Android.

1 Like

@R101 have you read my stackoverflow question ?

I just did, and it doesn’t make sense. You want to take a screenshot, done, you’ve been provided with 2 ways to do so, the captureScreen() and the RenderTexture methods. Anything other than that is something you have to figure out, like the permission issue that you mentioned in your SO post. I have nothing further to add to this.

1 Like

and cpp-tests has examples of both of these concepts.

@R101 & @slackmoehrle Thanks a lot for your guidance let me have look and done this :slight_smile:

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

std::string str =  CCFileUtils::sharedFileUtils()->getWritablePath();
str.append("/imageNameToSave.png");
const char * c = str.c_str();
texture->saveToFile(c);
SaveImageAndroidJNI(true);

#else

This code is now not working i checked cpp-test as you told me to do that but when i try to get image on android it shows me blank Look at my updated question

Please post more code. Show us a complete function of what you are doing so we can look at the entirety versus just snippets. Probably there is a small mistake. What you are doing is fairly common normally.

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

std::string str =  CCFileUtils::sharedFileUtils()->getWritablePath();
str.append("/imageNameToSave.png");
const char * c = str.c_str();
tex->saveToFile(c);

this->scheduleOnce(schedule_selector(Dressup_screen_BG_button_view::Photo_Save_Gallery_Android),1.0);

#else

tex->saveToFile("imageNameToSave.png", kCCImageFormatPNG);
this->scheduleOnce(schedule_selector(Dressup_screen_BG_button_view::Photo_Save_Gallery),1.0);
#endif


// This is native method which will save photo 
-( void )ThisPhotoClick{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *yourArtPath = [documentsDirectory 
stringByAppendingPathComponent:@"/imageNameToSave.png"];

UIImage *image = [UIImage imageWithContentsOfFile:yourArtPath];

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert !" message:@"Photo Saved To 
Photos." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];}

Android Method

public  static void SaveImageAndroidJNI(final boolean visible){


ContextWrapper c = new ContextWrapper(me);
String path = c.getFilesDir().getPath() + "/imageNameToSave.png";
System.out.println("Paht to check --"+path);
File imgFile = new File(path);

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse(path));

OutputStream output;
// Find the SD Card path



File filepath = Environment.getExternalStorageDirectory();

// Create a new folder in SD Card
File dir = new File(filepath.getAbsolutePath()
        + "/Your Folder Name/");
dir.mkdirs();

// Create a name for the saved image
File file = new File(dir, "imageNameToSave.png");

try {

    output = new FileOutputStream(file);

    // Compress into png format image from 0% - 100%
    myBitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
    output.flush();
    output.close();
}

catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}


Intent intent = new Intent();
Uri pngUri = Uri.fromFile(file);


intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, pngUri);
intent.setType("image/jpeg");

me.startActivity(Intent.createChooser(intent, "Share Image"));
}

Let me know if anything is still needed

I’m having trouble following what you are doing. Are you doing this on Android or iOS? You are posting objective-C code. Are you using AppPortable or something to run Objective-C on Android?

I want for android ,no i’m not using any appPortable code is written in cocos2dx3.17 and we just compile it for android, there is android method too look at that @zhangxm @slackmoehrle

Why the objective c?

Is there any way to save image in android than i don’t know so i follow the code from stackoverflow and that code is work fine for ios but for android nothing work for me if getWritablePath is worked than image should be in there but there is nothing

As well @slackmoehrle
Q :slight_smile: Why the objective c?
Ans: If any other way to take screenshot of current screen in android than pls let me know because it’s not native android code so we can’t take screenshot with getWindow().getDecorView().getRootView();

I’m not clearly understanding what you have and what you don’t.

@R101 provided you with captureScreen and I RenderTexture and writing it out is trivial. This works for me on my Android tablet.

Can you pls post here your working code here for me ? I know there must be a silly mistake by me but i couldn’t find out it so if you post your cocos & android both methods here than it glad to me

@slackmoehrle pls post methods

Please use cpp-tests. What you need is there