Solved

drawImage method only paints partial image (when image is loaded from Jar)

Posted on 2002-07-19
4
302 Views
Last Modified: 2010-05-18
I have a Java application that loads gif images and paints them in a JPanel.  It works great until I deploy that application in a Jar, then it only paints the top 25% of the image.  I've tried using both a compressed jar and an uncompressed jar, and the results are the same.

I am using MediaTracker to ensure that the image is completely loaded with no errors before I paint the image.  But the image still doens't display correctly.



0
Comment
Question by:AGE_Nicolls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Author Comment

by:AGE_Nicolls
ID: 7166024
Never mind.  I've figured it out.  For those interested, here is what I've found:

I was loading images as follows:

==========================================================
Image img;
InputStream in = getClass().getResourceAsStream("x.gif");
byte[] bytes = new byte[in.available()];
in.read(bytes);
img = Toolkit.getDefaultToolkit().createImage(bytes);
==========================================================                

When I changed the code to use getResource() instead of getResourceAsStream - it not only fixed the prblem, but simplified my code as well.


==========================================================
URL resUrl = getClass().getResource(resourceName);
img = Toolkit.getDefaultToolkit().createImage(resUrl);
==========================================================

I'd like to delete this question, but I'm not sure how...

-Matt
0
 
LVL 92

Expert Comment

by:objects
ID: 7166187
in.read(bytes);

Your problem was that the line above does not necessarily read all the bytes.
0
 
LVL 1

Author Comment

by:AGE_Nicolls
ID: 7169669
That's interesting...  When I checked the size of the byte array, it matched the size of the file.  I'll keep that in mind in the future though.

-Matt
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 7170537
points refunded and placed in PAQ

Computer101
E-E Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

635 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