Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

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.
0 Kudos
6 Replies
Highlighted
Level 7

Re: How to obtain photo dimensions on the Roku box?

There is no way to determine this from the SDK. Most photo providers give this information in their APIs.
0 Kudos
Highlighted
Level 7

Re: How to obtain photo dimensions on the Roku box?

"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.
0 Kudos
Highlighted
Level 7

Re: How to obtain photo dimensions on the Roku box?

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.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
Highlighted
Level 7

Re: How to obtain photo dimensions on the Roku box?

I'm always amazed at the interesting solutions people come up with to figure out these problems.
0 Kudos
Highlighted
Level 17

Re: How to obtain photo dimensions on the Roku box?

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
0 Kudos
Highlighted
Level 7

Re: How to obtain photo dimensions on the Roku box?

"renojim" wrote:
For jpegs, pass an roByteArray:


Thank you very much JT and others for your help.

Truly appreciate it.
0 Kudos