wgilster
asked on
MediaTracker, but no Component
I need to load images using an application but I don't have any components to construct a mediatracker. What is most commonly done in this case? Is there a component somewhere in the toolkit for this, or do I just create my own. I realize I can do this:
new MediaTracker(new JLabel());
But why isn't their a default constructor for such a common case? Am I missing something?
new MediaTracker(new JLabel());
But why isn't their a default constructor for such a common case? Am I missing something?
ASKER
Great for 1.4 but what about 1.3? No ImageIO class
>>but what about 1.3?
You can make things easier by doing
Image image = new ImageIcon("x.jpg").getImag e();
You can make things easier by doing
Image image = new ImageIcon("x.jpg").getImag
ASKER
I have a stream of bytes, not a filename that will be turned into an image.
Use a ByteArrayOutputStream (let it be 'baos') and then do
Image image = new ImageIcon(baos.toByteArray ()).getIma ge();
Image image = new ImageIcon(baos.toByteArray
ASKER
Great for 1.4 but what about 1.3? No ByteArrayOutputStream class.
Do I have to read it into an array? If so, let's get back to the mediatracker...
Do I have to read it into an array? If so, let's get back to the mediatracker...
ASKER
Sorry, My bad, ByteArrayOutputStream is there.
Do I have to write my inputstream to the outputstream?
Do I have to write my inputstream to the outputstream?
>>No ByteArrayOutputStream class.
It has been in the API since Java 1.0
It has been in the API since Java 1.0
>>Do I have to write my inputstream to the outputstream?
You read the bytes from your 'stream of bytes' then write them to the baos
You read the bytes from your 'stream of bytes' then write them to the baos
ASKER
I figured it out, ImageIcon uses a mediatracker with an anonymous class like this...
protected final static Component component = new Component() {};
protected final static MediaTracker tracker = new MediaTracker(component);
That's what I'll do.
protected final static Component component = new Component() {};
protected final static MediaTracker tracker = new MediaTracker(component);
That's what I'll do.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My entire class was based around the MediaTracker with a null parameter, but I kept getting NullPointerExceptions. I won't have to change my program at all this way. But you led me to the answer...
8-)
http://oldlook.experts-exchange.com/questions/21202103/Crop-jpg-image.html