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?
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.
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