Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ImageComponent - bounds and null images (Read 2612 times)
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
ImageComponent - bounds and null images
Apr 10th, 2015 at 1:20pm
Print Post  
Getting some functionality which seems a bit odd to me.

If I call setImage() on an ImageComponent with a null value, then call getBounds() on the same component, I get the bounds of any previous actual image.

If I then save the ImageComponent to XML, then call getBounds() on it, the returned height is zero, but the width is not changed (i.e. the width of the previous actual image).

If I then call setImage() on the same component with a real image (not null), then call getBounds() on it, I get the old width and zero height.

If I then save the ImageComponent to XML, then call getBounds() on it, I get the correct dimensions of the image.

This is causing problems when I try to resize the CompositeNode holding the ImageComponent to fit the image (and other components).

I would expect the following results:

Image set to null, getBounds() returns zero height and zero width.

Image set to an image, getBounds() returns the dimensions of the image.

I would not expect to have to save to XML after calling setImage() to get the expected results from getBounds().

Are my expectations incorrect, and if so can you please explain why?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ImageComponent - bounds and null images
Reply #1 - Apr 10th, 2015 at 4:48pm
Print Post  
Bounds value is not valid until CompositeNode.arrangeComponents has been called, which is usually done lazily on first draw after modifications of component properties. You could either call arrangeComponents yourself before querying Bounds, or use getDesiredSize method as in the resizeToFitText example from this thread:
http://mindfusion.eu/Forum/YaBB.pl?num=1422027320

I think correct width with zero heights might also be reported if Java hasn't yet completed loading an image, which it does asynchronously. You might try using ImageObserver or MediaTracker as in examples here to make sure images are fully loaded before trying to get their sizes:
http://web.mit.edu/1.124/LectureNotes/images.html

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint