Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Graphics.drawImage() not appearing right on Win 98

Posted on 2001-07-03
6
Medium Priority
?
200 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 1200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

618 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