Solved

Graphics.drawImage() not appearing right on Win 98

Posted on 2001-07-03
6
194 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
[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
6 Comments
 
LVL 3

Accepted Solution

by:
yuri1976 earned 300 total points
ID: 6248824
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
ID: 6248828
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
ID: 6249144
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
Technology Partners: 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!

 
LVL 16

Expert Comment

by:Valeri
ID: 6249636
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
ID: 6252666
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
ID: 6256635
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 39
jsp login check 12 52
pagenation logic how it is working in my code 1 69
glassfish admin console 1 21
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 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