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: 
OG_OTT
Visitor

Get Poster/image dimensions

I have created my own component by extending "group".  I have an image that I put into this group, and I want my brs to capture the width/height of that element so I can start to calculate where to place other components (like Labels) around it... but when I try to do this, I always get widths/heights of '0'.    

As such, I have found that if I set an observer on the "loadStatus" and wait until it is ready, I can get the bitmap dimensions.  This sounds like a great idea!  Now, once I know the image size I can make all the adjustments I need (at least for my situation).

Question:  Is this typical or the 'correct' pattern I should be following?  Or in RSG, is there an alternative way to set 'relative layout' around an image?
0 Kudos
3 REPLIES 3
joetesta
Roku Guru

Re: Get Poster/image dimensions

One way to get the on-screen dimensions of a node is to use https://sdkdocs.roku.com/display/sdkdoc/ifSGNodeBoundingRect#ifSGNodeBoundingRect-boundingRect() node.boundingRect().width and node.boundingRect().height
aspiring
0 Kudos
OG_OTT
Visitor

Re: Get Poster/image dimensions

Hmm, I'd have to test it, BUT, I think I already tried that.  The problem being, and I have seen multiple instances of this, when setting up an initial screen and the components haven't been rendered or scaled, the heigh/width is coming back as 0, and I THINK (again, I'd have to explicitly test) the boundingRect() is also coming back as either 0's OR it has the raw dimensions (because it hasn't been scaled yet).  As such, because things have not been rendered and I don't know the final values, I defaulted to the "loadStatus" observer.  

So to be clear, 100% acknowledge your recommendation, and I'll test it out to be 100% certain it does or doesn't work, but this is on screen init() and BEFORE anything is visible to the user/rendered, so I don't think the values (from what I remember when I wrote this a few days ago) were accurately set/ready for me to consume.  

I hope that makes sense - what are your thoughts?

Thanks again JoeTesta - you've been really helpful in answering all of my beginner questions!  You'll be happy to know that I have been more carefully reading the docs - especially those yellow CTA's =P. 
0 Kudos
joetesta
Roku Guru

Re: Get Poster/image dimensions

As long as the component is defined in xml, boundingRect() works correctly in the component's init()
cheers,
Joe
aspiring
0 Kudos