[Solved] How to get image data in Native?

Using Cocos Creator, in my script I can access the image and the data of a texture by calling cc.Texture2D.getHtmlElementObj() when the game runs on the web/HTML5, but how can I achieve the same when in a native system?

I get the error getHtmlElementObj() is not a function when I try to run it in the simulator, which I guess I can understand because there is no HTML or DOM elements in a native system. cc._renderContext is also undefined in native.

If so, what is the best way to access a texture image’s raw data(pixel information) in native system? I would like to be able to access the texture image’s data in all platforms.

Adding some notes here, hopefully it may help others in the future.

After days of experimenting I found that there was no way to pass image data from the native codes to the javascript side. The best one can do is to obtain the image data from the native codes (C++) and do whatever that needs to be done in C++ instead of trying to pass it to the JS side of things.

You can opt to either modify the existing cpp classes that are dealing with images before creating the texture (not good), or you can built your own cpp extension classes to do that. But in terms of trying to do it in JS on CocosCreator, I had no luck.

Maybe, these links below will help you.