How to load a texture from android MediaStore?

Hi guys,

I need to load an image from android MediaStore content provider and display it as a Texture for an object. What is the best way to do this task? The “obvious” way for me would be using MediaStore.Images.Media.getBitmap(ContentResolver cr, Uri url) to load an android bitmap object, then convert it into jmonkey Image object, then use the Image to create the Texture. Is there any problem with this approach? And is there a better way to do it?

Thanks in advance.

You can use an URLLocator and then just load it via the assetManager.

Thanks for a super quick reply normen :). Can you give more detail? Suppose I use ACTION_PICK to launch the picking activity and in my onActivityResult I got an Uri object. With that object I can query the path of the image in my device (as a String). However, I did not figure out how to use the URLLocator to load it via assetManager yet.

You use it like any locator, check the HelloAssets tutorial.

I still dont know how to use URLLocator in this case. The thing is, I dont know what to use as the root. Anyway, I tried FileLocator instead and it worked. Supposed I got the path to the image file stored in String imageLocation, then this is what I did:


myApp.getAssetManager().registerLocator("/", FileLocator.class.getName());

Texture texture = myApp.getAssetManager().loadTexture( picturePath );


1 Like

BTW, thanks for the pointer to the HelloAssets, normen.