Solved

Graphics.drawImage() not appearing right on Win 98

Posted on 2001-07-03
6
190 Views
Last Modified: 2008-03-10
This is my paint method:

     public void paint( Graphics g )
     {
          g.drawImage( m_im4, 25, 50, this );
          g.drawImage( m_im5, 25, 100, this );
          g.drawImage( m_im6, 25, 130, this );
          super.paint( g );
     }
Win 98 running IE5 (JVM 5.00.3802)
The display properties are true colour 24 bit 1024 X 768
The images are coming out distorted.
Is there a solution to this?

0
Comment
Question by:zedkaufmann
6 Comments
 
LVL 3

Accepted Solution

by:
yuri1976 earned 300 total points
Comment Utility
what is contained in m_im4, m_im5, m_im6? What I mean is: how do you fill those images, that you use to paint on the component?

What is the size of the component that you're trying to paint on?

In what aspect is the outcome distorted?

Why do you use super.paint(g) as the last statement?
0
 
LVL 16

Expert Comment

by:Valeri
Comment Utility
Take a look at all drawImage methods of Graphics class. In Java 1.3.1 API they are 6.

public abstract boolean drawImage(Image img,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  Color bgcolor,
                                  ImageObserver observer)
It is the third one.... I think it will help you.

Best regards,
valeri
0
 

Author Comment

by:zedkaufmann
Comment Utility
To Yuri1976:
1)This is how the image is loaded:
    public static Image loadImage( Component comp,
    String  imageURL )
    {
        Image image = null;
        try
        {
            URL url = new URL( imageURL );
            MediaTracker mt = new MediaTracker( comp );
            image = Toolkit.getDefaultToolkit().getImage(
            url );
            mt.addImage( image, 0);
            mt.waitForAll();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return image;
    }
2) The size of the image is approx 500 wide by 40 high
3) The backcolor is black (instead of light blue)and the  
   definition is very fuzzy.
4) I need to call super(g) to draw the rest of the screen-
   should it be called first?
Do those answers give you any clues?

To Valeri:
can I pass in null for an imageObserver?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 16

Expert Comment

by:Valeri
Comment Utility
This method returns immediately in all cases, even if the entire image has not yet been scaled, dithered, and converted for the current output device. If the current output representation is not yet complete then drawImage returns false. As more of the image becomes available, the process that draws the image notifies the specified image observer. In my opinion it means that you can pass null pointer to ImageObserver. Just try....

I hope it will help you.
Best Regards,
Valeri
0
 
LVL 3

Expert Comment

by:yuri1976
Comment Utility
1) Seems to be the right way to do this
2) Your wordchoice confuses me. Do you mean component when you say 'image'? So: The size of the component is approx 500 by 40? Or is the size of the 3 different images 500x40?
3) Strange behavior... Do you have this only in this program or are all your java programs corrupted like this?
4) Normally you call super.paint first because you never know what's going to be painted before you enter. Suppose your super.paint method wipes the contents of the whole component and draws some lines or text. Then you can draw wonderfull images on the component, but they are all wiped again by the last super.paint call.

What I'm still wondering about : you call drawimage with 'this' as the ImageObserver. I probably would've just left this at null. Why would you want the component to observe the image?
0
 
LVL 1

Expert Comment

by:llaurick
Comment Utility
What do you mean they are comming out distorted? In what way?
If the images have not finished beeing created, then you could get only part of the images, a bit like when you see only the upper part of an image in a abrowser, but they would not come distorted. Your loadImage method seems right and the iamges should all have been loaded because of the waitForAll. So the distortion is not a load problam.
Are you sure your images don't overlapped?
Do they have a transparency color?
What kind of image is it? gif? jpg?

I would suggest you try to draw only one image at a time, to see if each draws ok. If yes, then try two.

Hope this helps,

Llaurick.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now