How do you get the bit depth of a image?

Is there a easy way or a way to get the bit depth of a loaded image?

I know I can go to properties then details on the computer (windows) but how do I get the output to tell me?

@joshjarc - I can only think of two ways to get this information, but neither of these is simple. I believe that when Solar2D reads in image files, it converts that file to display in the format of the target display and does not make the 8, 16, 24 or 32-bit data point available to us.

  1. ACCURATE, but some work - first read the file as a binary image and check it’s format from its data, so you’ll need to familiarize yourself with the different file types and how the bit depth is stored; or

  2. sample the image as it appears on screen to see if more than 256 colors are used; if more, assume it’s 16, 24 or 32-bit.

As far as checking its format I can get output to print the format(ex.PNG) but not sure how to view bit depth from that.
Link I was following to read the file https://docs.coronalabs.com/guide/data/readWriteFiles/index.html

Could this plugin help me retrieve the bit depth info?
https://docs.coronalabs.com/plugin/memoryBitmap/index.html
if so, how do you install the plugin(already activated)

Option 2
for color sampling I used the link
https://docs.coronalabs.com/api/library/display/colorSample.html
I got it to print(R,G,B,A) of color position on screen but how would I check to see if 256 colors are used with that information?

It’s a real slow method but you scan the document and keep adding only new RGB values to a list until the count is > 256. The other method requires more research to understand various file formats but would likely be fast and perfect.

Is this what you mean when you say read the file as a binary image and check its format from its data?

local params = {}

params.bodyType = "binary"

local function networkListener( event )

    if ( event.isError ) then

        print ( "Network error - download failed" )

    else

        event.target.alpha = 0

        transition.to( event.target, { alpha = 1.0 } )

    end

    print ( "event.response.fullPath: ", event.response.fullPath )

    print ( "event.response.filename: ", event.response.filename )

    print ( "event.response.baseDirectory: ", event.response.baseDirectory )

end

  

display.loadRemoteImage( "https://i1.wp.com/blog.thejaytray.com/wp-content/uploads/2018/04/Capture.png?resize=300%2C276", "GET", networkListener, params, "coronalogogrey.png", system.TemporaryDirectory, 300, 400 )

-- Path for the file to read

local path = system.pathForFile( "coronalogogrey.png", system.TemporaryDirectory )

 

-- Open the file handle

local file, errorString = io.open( path, "r" )

 

if not file then

    -- Error occurred; output the cause

    print( "File error: " .. errorString )

else

    -- Read data from file

    local contents = file:read( "*a" )

    -- Output the file contents

    print( "Contents of " .. path .. "\n" .. contents )

    -- Close the file handle

    io.close( file )

end

 

file = nil

You’re onto the right idea, but look again at the API for this: https://docs.coronalabs.com/api/library/io/open.html

Notice this text: The mode string can also have a 'b' at the end, which is needed in some systems to open the file in binary mode. This string is exactly what is used in the standard C function fopen.

So, you see that you need to add the “b” at the end?

Once you have loaded the image as a binary file, you should be able to parse your way through to get the information you’d like, depending upon the file type you want to look into. Are you needing this only for PNG? Or for other formats?

I have an info function in my impack plugin. (This is now in the free plugins.) Doesn’t look like I have it in the example, but its signature is basically like what you see with image.load.

What are you trying to do?