Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
davinceo
Visitor

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 6
hoffmcs
Visitor

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
davinceo
Visitor

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
kbenson
Visitor

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
hoffmcs
Visitor

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
renojim
Community Streaming Expert

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
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
davinceo
Visitor

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.