Plugins Byte Map: error running on Android

Hello StarCrunch,

Referencing earlier thread, “How to sample the color of a pixel of an image”,

https://forums.coronalabs.com/topic/73593-how-to-sample-the-color-of-a-pixel-of-an-image/?hl=pixel

After adding more codes to my program and successfully testing on Simulator/Windows, I am now ready to test deploy on Android. I immediately get an error. I strip the code down to bare minimum. It also gives the same error.

The environment are, Corona Simulator 2018.3258 (Apr 04, 2018) on Windows 10. Tested Android device is a Samsung tablet, v4.4.2, and a LG G4 mobile phone, v6.0. Both devices give same error as below. Build settings has the plugin configured and codes (bare-bone test code and my program) run successfully on Simulator/Windows.

Error message,

“attempt to index local “bm” (a nil value)”

Bare-bone test code, failed with error message above,

local Bytemap = require "plugin.Bytemap" local bm = Bytemap.loadTexture( {     filename = "picture1.png",     baseDir = system.ResourcesDirectory, } ) local w, h = bm.width, bm.height local alpha = bm:GetBytes( {     format = "alpha", } )-- alternatively can grab single pixel here print( bm, w, h, type( alpha ), string.len( alpha ) )

Would appreciate your help again on this.

Thank you.

Regards, Luan

Hi Luan. This is a consequence of Android having a zip-ish structure, so there really isn’t any resource directory. A bunch of formats won’t even load, and I believe others get copied to the temporary directory or something similar.

I actually made another plugin a few weeks ago (when I was adding the loadTexture() function, in fact) to address this: AssetReader (it’s also alluded to in the Bytemap docs).

If you require() that plugin some time before your load call, it ought to work. (It should be harmless to do this even on non-Android code too.) I was hoping to make this dependency automatic, but haven’t figured that out yet.

Hello StarCrunch,

Thank you for your prompt response. You did mention the “AssetReader” in the earlier “sample the color of a pixel” thread. I just did not understand its significance until now. I suppose I was focused on getting this “getPixel” functionality for my program.

I have downloaded the demo program for “AssetReader”. It ran successfully on my Samsung tablet v4.4.2.

However, how do I “feed” the content of “AssetReader” into “ByteMap”? Do I use the content from asset_reader.Read() to put into Bytemap.loadTexture() or Bytemap.NewTexture() or Bytemap.BindBlod()?

Would appreciate your guidance again. Thanks.

Regards, Luan

Hi Luan.

Nothing else needed on your end, other than adding AssetReader to build.settings and require()'ing it. If the Bytemap plugin sees it’s available, it’ll call the appropriate routines itself.

Hello StarCrunch,

Thank you for your prompt response. I did some quick test. It works well on my Samsung tablet v4.4.2.

It is interesting that it could detect the plugin and does it automatically.

Thanks!

Regards, Luan

PS> For those who may be keen on these plugins for reading and writing image pixel byte info from stream and other uses, from StarCrunch,

Byte Map, https://marketplace.coronalabs.com/corona-plugins/byte-map

Asset Reader, https://marketplace.coronalabs.com/corona-plugins/assetreader