ImagePicker JNI method dont work

hi all. I uploaded a picture from the gallery, i using the jni method but the sprite is empty.
this is the code.

java function

 @Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode != IMAGE_PICKER_ACTIVITY)
    {
        return false;
    }
    if (resultCode == Activity.RESULT_OK)
    {
        Uri imageUri = data.getData(); 
              
        try 
        {  
        	//String path = getPath(imageUri);
        	InputStream is = Cocos2dxHelper.getActivity().getContentResolver().openInputStream(imageUri);
            ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
            int bufferSize = 10240;
            byte[] buffer = new byte[bufferSize];

            int len = 0;
            while ((len = is.read(buffer)) != -1)
            {
                byteBuffer.write(buffer, 0, len);
            }
            is.close();
        	
            ImagePickerResult(byteBuffer.toByteArray());
          
            return true;
        
        } 
        catch (Exception e){}
    }
   
    ImagePickerResult(null);
    return false;
}

cocos2d-x jni function

    extern "C" 
{
     void Java_org_cocos2dx_lib_Cocos2dxImagePicker_ImagePickerResult(JNIEnv *env, jobject thiz, jbyteArray byteArray)
    {
        if(byteArray != NULL)
		{
        	jsize lengthOfArray = env->GetArrayLength(byteArray);
        	jbyte* bufferPtr = env->GetByteArrayElements(byteArray, NULL);
            Image *image = new Image();
            image->initWithImageData((unsigned char*)bufferPtr, lengthOfArray);
        	env->ReleaseByteArrayElements(byteArray, bufferPtr, 0);  
			Texture2D* texture = new Texture2D();
			texture->initWithImage(image);

			ImagePicker::getInstance()->finishImage(texture);
        }
        else
		{
            Director::getInstance()->getScheduler()->performFunctionInCocosThread([]
			{
                ImagePicker::getInstance()->finishImage(nullptr);
            });
        }

helloWorld.cpp init

auto imagepicker = new PhotoPicker();

auto picker = ImagePicker::getInstance();
picker->pickImage(imagepicker);

auto image = imagepicker->getSelectedPhoto();

if (image){
	image->setPosition(getContentSize() / 2);
	addChild(image);
}

simply classes

    static ImagePicker* sharedPicker = nullptr;

ImagePicker::ImagePicker()
{
    _delegate = nullptr;
}

ImagePicker* ImagePicker::getInstance()
{
    if(sharedPicker == nullptr)
	{
        sharedPicker = new ImagePicker();
    }
    return sharedPicker;
}

void ImagePicker::pickImage(ImagePickerDelegate *delegate)
{
    _delegate = delegate; 
    ImagePickerImpl::openImage();
}

void ImagePicker::finishImage(cocos2d::Texture2D* image)
{
    if(_delegate != nullptr)
	{
        _delegate->didFinishPickingWithResult(image);
    }
}

//PHOTOPICKER---------------------------------------------------

PhotoPicker::PhotoPicker()
{ 
	result = nullptr;
}

PhotoPicker::~PhotoPicker(){}

void PhotoPicker::didFinishPickingWithResult(Texture2D* result)
{
	this->result = result;
}

Sprite* PhotoPicker::getSelectedPhoto()
{
	if (result)
	{
		return Sprite::createWithTexture(result);
	}

	return nullptr;
}

//-----------------------------------------------------------

in the helloworld cpp the sprite is empty and also the texture. I can not understand the problem

up…nobody?

@Asasola

You may check this image picker which i using with Cocos2d-JS

It is the same that I used

@Asasola

I have no problem using it with Cocos2d-JS v3.6.1 and v3.7 in JSB.

But i not sure the proper way to use it in C++, so you may try contact the author

hi, did u find a working solution for this?