Link to home
Start Free TrialLog in
Avatar of zedkaufmann
zedkaufmann

asked on

Graphics.drawImage() not appearing right on Win 98

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?

ASKER CERTIFIED SOLUTION
Avatar of yuri1976
yuri1976

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Valeri
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
Avatar of zedkaufmann
zedkaufmann

ASKER

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?
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
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?
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.