?
Solved

Get Image

Posted on 2005-04-19
19
Medium Priority
?
250 Views
Last Modified: 2010-03-31
Dear Experts,

           I have a java class. This class will get the image. It is running well and no exception thrown. But, when I deploy to the linux server, and put it in the tomcat, it still can run, but, when come to period of time, this class will stop before the code below and there is no exception thrown:

            Image image = Toolkit.getDefaultToolkit().getImage(inFile);

          Once I restart my tomcat, this class can still run without error. Can someone tell me what is the problem? Any idea to overcome this problem?

          This is part of my code:

            Image image = Toolkit.getDefaultToolkit().getImage(inFile);
            MediaTracker mediaTracker = new MediaTracker(new Frame());
            mediaTracker.addImage(image, 0);
            mediaTracker.waitForID(0);
            BufferedImage sImage = new BufferedImage(width,
                  height, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = sImage.createGraphics();
            graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                  RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics2D.drawImage(image, 0, 0, width, height, null);
            BufferedOutputStream out = new BufferedOutputStream(new
                  FileOutputStream(outFile));
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(sImage);
            quality = Math.max(0, Math.min(quality, 100));
            param.setQuality((float)quality / 100.0f, false);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(sImage);


Regards,
  Jocelyn
0
Comment
Question by:jocelynyip
  • 9
  • 8
17 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822114
>>this class will stop before the code below and there is no exception thrown:

Are you certain there's no exception? What is happening just prior to that code being called?
0
 

Author Comment

by:jocelynyip
ID: 13822157
Yes, I am sure.

For an example:

System.out.println("Start Get Image!!!");
Image image = Toolkit.getDefaultToolkit().getImage(inFile);
System.out.println("End Get Image!!!");

In the console, I just can see "Start Get Image", and the println just stop here and from the console, I can't see any exception thrown. So, I know that there is problem with this code --> Image image = Toolkit.getDefaultToolkit().getImage(inFile);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822178
>>In the console, I just can see "Start Get Image",

How can you see the console if you're running in Tomcat?

>>ut, when I deploy to the linux server, and put it in the tomcat, it still can run, but ...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:CEHJ
ID: 13822193
e.g. if that image file is outside the web context, your code will crash in a web container
0
 

Author Comment

by:jocelynyip
ID: 13822217
I can see it throught the log catalina.out.

My code can run for a period of time and over a period of time, the code will stop at the code Image image = Toolkit.getDefaultToolkit().getImage(inFile);

I have to restart tomcat, and my code is running. That means that everytime it down, I have to restart tomcat to make it running.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822230
OK, so sometimes is *does* render the image ok using Tomcat ..?
0
 

Author Comment

by:jocelynyip
ID: 13822241
yes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822277
OK - we can rule out security issues then. Is this image by any chance a large one?
0
 

Author Comment

by:jocelynyip
ID: 13822303
What u mean by rule out security issue? The image size is 176x134
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822318
>> What u mean by rule out security issue?

Problems due to the security policy of your web container

>>The image size is 176x134

Well i meant the file size, but i take it from that it's not large ;-)
0
 

Author Comment

by:jocelynyip
ID: 13822355
The file is not big, ard 60kb, some is only 17kb
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822390
>>In the console, I just can see "Start Get Image", and the println just stop here

Is this *always* the case?

I'll imagine the above says 'In the log file' - it's confusing ;-)
0
 

Author Comment

by:jocelynyip
ID: 13822432
sorry, is the log will show the println.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13822515
But you didn't answer the question:

>>Is this *always* the case?
0
 

Author Comment

by:jocelynyip
ID: 13822564
Everyday has such problem. Quite frequent.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 13822574
I'm not sure what's causing this but instead of:

>>
Image image = Toolkit.getDefaultToolkit().getImage(inFile);
MediaTracker mediaTracker = new MediaTracker(new Frame());
mediaTracker.addImage(image, 0);
mediaTracker.waitForID(0);
>>

Try


Image image = new ImageIcon(inFile).getImage();
0
 

Author Comment

by:jocelynyip
ID: 13822605
ok, thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question