How to obtain photo dimensions on the Roku box?

Hi All:

How do I determine/obtain photo dimensions (width and height) right on the Roku box. Assume that photo dimensions are not available from the source where I get the photos. Are there any APIs available on the Roku SDK to read the photo headers to get the width and height info?

Appreciate any pointers.

There is no way to determine this from the SDK. Most photo providers give this information in their APIs.

“hoffmcs” wrote:
There is no way to determine this from the SDK. Most photo providers give this information in their APIs.

Thank you for your response.

Looks like if you are pulling photos from a USB for instance, you cannot determine the dimensions.

Well, you CAN, it’s just you have to be dedicated. You can read the image into an roByteArray, parse the jpeg/png headers, and pull the dimensions.

If you are willing to wait a week, we’ll be open sourcing something easily modifiable to do this for PNG images. I don’t imagine it’s much harder for JPEG.

I’m always amazed at the interesting solutions people come up with to figure out these problems.

For jpegs, pass an roByteArray:

Function GetJpegDimensions(jpeg as Object) as Dynamic
    if jpeg[0] <> &HFF or jpeg[1] <> &HD8 then return invalid
    i = 2
    w = 0
    h = 0
    len = jpeg.Count()
    while true
        soi1 = jpeg[i]
        soi2 = jpeg[i+1]
        if soi1 = &HFF and (soi2 = &HC0 or soi2 = &HC2) then
            h = jpeg[i+5]*256 + jpeg[i+6]
            w = jpeg[i+7]*256 + jpeg[i+8]
            exit while
        end if
        cnt = jpeg[i+2]*256 + jpeg[i+3]
        i = i + cnt + 2
        if i >= len then
            print "Could not find jpeg dimensions!!!"
            return invalid
        end if
    end while
    return {w:w,h:h}
End Function

-JT

“renojim” wrote:
For jpegs, pass an roByteArray:

Thank you very much JT and others for your help.

Truly appreciate it.