Solved

Graphics.drawImage() not appearing right on Win 98

Posted on 2001-07-03
6
192 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JUnit 4 @Before and @BeforeClass differences 3 59
HSSFWorkbook cannot be resolved error 10 69
more than one jdk and one jre 1 41
difference of if loops 23 49
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

770 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