Draw image in a indexed bufferedimage

When i draw a image in a indexed bufferedimage the destination image is distorted. As source image i use a 256 color gif image. But when i use a TYPE_INT_RGB bufferedimage it's all good. I don't get it. Here's a is the simple code i'm using.
Image image = new ImageIcon("E:/Java/MapEdJava/MapEditor/pics/"+ImageName).getImage());
BufferedImage bi = new BufferedImage(image.getWidth(this),image.getHeight(this) , BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(image, 0, 0, this);

First, a plea to all posters: if you write "why does my code do this..." either include a brief program that recreates the problem, or give the url to such code. On one hand, posting a long listing doesn't encourage assistence from the forum -- you should be motivated enough to recreate your problem "in the small". On the other hand, not posting enough information doesn't help either: for example, if a particular image is giving you grief, include its url, or find an image with a publicly-reachable url. [Getting off soapbox :-]
Here's some quick&dirty code that, perhaps, demonstrates the poster's problem. It features a certain bald, chunky guy (no, not me!)
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class ImageTest extends JComponent {
     public static void main(String[] args) throws java.io.IOException {
          java.net.URL url = new java.net.URL(
"http://java.sun.com/people/jag/JagWithDukeSmall.gif");
          JFrame frame = new JFrame(url.toString());
          Image image1 = new ImageIcon(url).getImage();
          BufferedImage image2 = javax.imageio.ImageIO.read(url);
          BufferedImage image3 = new BufferedImage(image2.getWidth(),image2.getHeight() ,
               BufferedImage.TYPE_BYTE_INDEXED);
          System.out.println("image2 colormodel="+image2.getColorModel().getClass().getName());
          System.out.println("image3 colormodel="+image3.getColorModel().getClass().getName());
          Graphics2D g2 = image3.createGraphics();
          g2.drawImage(image1, 0, 0, null);
          frame.getContentPane().add(new ImageTest(image1, image2, image3));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.show();
     Image im1, im2, im3;
     ImageTest(Image im1, Image im2, Image im3) { //assume loaded into memory
          this.im1 = im1; this.im2 = im2; this.im3 = im3;
     public Dimension getPreferredSize() {
          return new Dimension(3*im1.getWidth(null), im1.getHeight(null));
     protected void paintComponent(Graphics g) {
          g.drawImage(im1, 0, 0, null);
          g.drawImage(im2, im1.getWidth(null), 0, null);
          g.drawImage(im3, 2*im1.getWidth(null), 0, null);
}Why is the third image grainy? I tried adjusting g2's rendering hints, specifically KEY_COLOR_RENDERING and KEY_DITHERING, but I couldn't see any difference. Perhaps the graininess is because image3 is constructed with (I assume) a generic half-tone(?) IndexColorModel. If you know your image has lots of blues, you could construct an ICM with more blue-tones and pass it to constructor:
BufferedImage(int width, int height, int imageType, IndexColorModel cm)On the other hand, image2 has an ICM and it looks OK -- why not load images using java.imageio.ImageIO.read()?
--Paul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Having a problem with image IO and drawing image

    My question did not come out on the other posting. I am getting them image from a JPanel. I then convert the image into a renderedimage. Use the ImageIO.write method to convert to png format. I don't want to save the image on the local disk so it is writted to a ByteArrayOutputStream. I get the bytes from this and insert this into a blob field type.
    Then to paint the image onto the JPanel I try two methods to paint it on to the JPanel. I set the JPanel to be the width and size of the image. But I am getting a null pointer exception and I can't figure out why. If anyone could give me any suggestions I would really appreciate it.
    rImage = convertToRenderedImage(draw.drawPanel.offScreen, width11, drawPanelHeight, type);
    try{
    bo = new ByteArrayOutputStream();
    ImageIO.write(rImage, "png", bo);
    imageBytes = bo.toByteArray();
    }catch(IOException iox3)
    System.err.println(iox3);
    PreparedStatement statement12 = connection.prepareStatement(
    "INSERT INTO feed VALUES(?,?,?,?,?,?);");
    statement12.setBytes(2, imageBytes);
    icon = new ImageIcon(rs.getBytes("file"));
    image = icon.getImage();
    //base is the JPanel
    Graphics g2d = base.getGraphics();
    bytes = rs.getBytes("file");
    bInput = new ByteArrayInputStream(bytes);
    try
    bImage = ImageIO.read(bInput);
    catch(IOException e21)
    System.out.println("Error in imageIO transformation");
    //image is Image and bimage is bufferedimage
    image = bImage;
    Graphics g2d = base.getGraphics();
    g2d.drawImage(image, 0, 0, base);
    g2d.drawImage(image, 0, 0, base);

    Would it be possible for you to send out a small runnable testcase that I could try out with?
    Thanks,
    Kannan

  • How draw image into frame in applet

    How draw image into frame in applet.Please give my simple example code.

    http://search.java.sun.com/search/java/index.jsp?qt=%2Bdraw+%2Bimage+%2Bpanel+%2Bhow&nh=10&qp=&rf=1&since=&country=&language=&charset=&variant=&col=javaforums

  • Draw image using paint() only once.

    I am having performance issues with my application. It is creates a graph like data display. The display is static. However each time paint is called the image is re-rendered. I want it only rendered once to improve performance, I tried to do this using the following code:
    public void paint(Graphics g){
              if (alreadyRun) return;
              //super.paint(g);
              alreadyRun = true;
    // draw graphics code
    }Unfortunately the required image appears for a moment then disappears. Is there any way to render the image only once? Also, are there any other performance improving measures I can take? I was thinking of rendering only the part of the image that appears on screen (my graphics display is usually bigger than the actual screen size)

    The common way to deal with performance like this is to draw the graph (or whatever) onto a BufferedImage then have the paint (or paintComponent in Swing) simply draw the image. The single draw image is quite fast and keeps the pixel values persistant across paints. If you already have a single image as the thread title hints, the paint shouldn't create much of a performance hit. The reason you are seeing your image disappear is that any time a window is resized, repacked, moved, covered up, or a multitude of other reasons, it calls paint again, so even with static data, there will be times the paint method is called again, causing your drawing to disappear.

  • Drawing images in JComponent

    Hi,
    I have an application laid out as Figure 1 depicts.
    JFrame
    |
    | JMenuBar
    |-----------------------------------------
    | ------------------JPanel - appPanel
    | |--------------------------------|
    | | ---|------------------ JPanel - displayPanel
    | | | |
    | |----------------|---------------|
    | |-------------------------- JComponent - jcanvas
    |
    | |--------------------------------|
    | | ----|----------------------- JPanel - controlPanel
    | | |
    | |--------------------------------|
    |
    |--------------------------------------------
    Figure 1
    The problem I am having is that:
    theJPanel (appPanel) contains two JPanels (displayPanel and controlPanel) and I am adding a JComponent called JCanvas
    to the displayPanel and I use it to draw images on it of type BufferedImage. Now, the image is displayed without any problem
    but when I resize the application (JFrame) I lose my image. I know the JCanvas (JComponent) is being redrawn because I can
    temporarily see the image but something is overwriting the image. I have set appPanel, displayPanel, controlPanel to opaque
    but I still loose the image.
    Of point maybe, if I access the JMenuBar the image will appear less what part of the menu bar obscures it.
    The appPanel, controlPanel, and displayPanel are created in the IDE. Where as, the JCanvas is a seperate class extending JCompoment
    and it has it own paintComponent method to do the image rendering and is added to the displayPanel when instantiated.
    What I don't understand is why isn't the image staying visible after a frame resize?
    Thanks,
    Bob

    Hopefully this will fit.
    You will have to provide your own image file.
    * SwingPaintDemo2.java
    * Created on Sep 27, 2008, 10:57:22 AM
    * Company: 
    * Copyright: Sep 27, 2008
    * Version:
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.BorderFactory;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.imageio.ImageIO;
    import javax.swing.JComponent;
    * @author
    public class SwingPaintDemo2 {
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            System.out.println("Created GUI on EDT? " +
                SwingUtilities.isEventDispatchThread());
            JFrame f = new JFrame("Swing Paint Demo");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new MyPanel());
            f.pack();
            f.setVisible(true);
    class MyPanel extends JComponent {
        BufferedImage bi;
        File file;
        Dimension d = new Dimension();
        boolean fullScreen = false;
        public MyPanel() {
            setBorder(BorderFactory.createLineBorder(Color.black));
            file = new File("g://java/images/dido_img.jpg");
            try {
                bi = ImageIO.read(file);
            } catch (IOException ex) {
                Logger.getLogger(MyPanel.class.getName()).
                    log(Level.SEVERE, null, ex);
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(350, 350);
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) this.getGraphics();
            d = this.getPreferredSize();
            if (d.width == 0 || d.height == 0) {/* error */
            if (!fullScreen) {
                int px = (d.width - bi.getWidth()) / 2;
                int py = (d.height - bi.getHeight()) / 2;
                g2.drawImage(bi, null, px, py);
            } else {
                g2.drawImage(bi, 0, 0, d.width, d.height,
                    0, 0, bi.getWidth(), bi.getHeight(), null);
    }

  • Drawing Images. Making them Durable?

    Im trying to create an application that draws images to the screen. So for example, it draws an image (call it image x) where the user left clicks the mouse. It draws fine. Then when the user clicks at a new spot, the first image x is erased when the next is placed on the screen. This isn't what I want, I want all previous images from clicking to say. From searching, it seems my problem is that drawn images are not durable. Other forum posts didn't help me understand the solution to the problem so any help would be wonderful.
    Edited by: goyanks135 on May 12, 2009 6:13 PM

    Thanks for the quick reply, that seems to work best for this application. Another thing, is there any way to generate a BufferedImage that represents the panel? Currently I am using:
    <BufferedImage> = robot.createScreenCapture(<Rectangle>);
    to do so, but would not depending on where the window is on the screen. I couldn't figure out how to determine the windows location. Is there a method to create the BufferedImage or obtain the window's coordinates?
    edit: I was looking at the getLocation() and getSize() methods of the component class. Seems like they should work if I use
    <BufferedImage> = robot.createScreenCapture(new Rectangle (getLocation(), getSize());
    I'm going to bed right now and didn't get it to work. Seems like it should.
    Edited by: goyanks135 on May 12, 2009 7:01 PM

  • How can I draw image in a vbean?

    How can I draw image in a vbean?
    this is my code :
    import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.Graphics;
    import java.net.MalformedURLException;
    import java.net.URL;
    import com.sun.jimi.core.Jimi;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.VBean;
    public class PrintEmailLogo extends VBean {
         URL url;
         Image img;
         boolean ImageLoaded = false;
         public void paint(Graphics g) {
              if (ImageLoaded) {
                   System.out.println("yes~~~");
                   g.drawImage(img, 0, 0, null);
              } else
                   System.out.println("no~~~");
         public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
                   int h) {
              if (infoflags == ALLBITS) {
                   System.out.println("yes");
                   ImageLoaded = true;
                   repaint();
                   return false;
              } else
                   return true;
         public void init(IHandler arg0) {
              super.init(arg0);
              try {
                   url = new URL("file:print/77G.gif");
                   img = Jimi.getImage(url);
                   Image offScreenImage = createImage(size().width, size().height);
                   Graphics offScreenGC = offScreenImage.getGraphics();
                   System.out.println(offScreenGC.drawImage(img, 0, 0, this));
              } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    but when I run it in forms
    when it run Graphics offScreenGC = offScreenImage.getGraphics();
    It throw a exception:
    java.lang.NullPointerException     at com.avicit.aepcs.calendar.PrintEmailLogo.init(PrintEmailLogo.java:72)     at oracle.forms.handler.UICommon.instantiate(Unknown Source)     at oracle.forms.handler.UICommon.onCreate(Unknown Source)     at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)     at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)     at oracle.forms.engine.Runform.processMessage(Unknown Source)     at oracle.forms.engine.Runform.processSet(Unknown Source)     at oracle.forms.engine.Runform.onMessageReal(Unknown Source)     at oracle.forms.engine.Runform.onMessage(Unknown Source)     at oracle.forms.engine.Runform.processEventEnd(Unknown Source)     at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)     at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)     at java.awt.Component.dispatchEventImpl(Unknown Source)     at java.awt.Container.dispatchEventImpl(Unknown Source)     at java.awt.Component.dispatchEvent(Unknown Source)     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)     at java.awt.Container.dispatchEventImpl(Unknown Source)     at java.awt.Component.dispatchEvent(Unknown Source)     at java.awt.EventQueue.dispatchEvent(Unknown Source)     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)     at java.awt.EventDispatchThread.run(Unknown Source)
    I change it to:
    import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.Graphics;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.JFrame;
    import com.sun.jimi.core.Jimi;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.VBean;
    public class PrintEmailLogo extends VBean {
         URL url;
         Image img;
         public void paint(Graphics g) {
              try {
                   url = new URL("file:print/77G.gif");
                   img = Jimi.getImage(url);
                   g.drawImage(img, 0, 0, this));
              } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public void init(IHandler arg0) {
              super.init(arg0);
    But it display nothing.
    It isn't paint continuous.
    what's wrong in my vbean?
    please help me.

    The following code works fine for me:
    package oracle.forms.fd;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.CustomEvent;
    import oracle.forms.ui.VBean;
    public class test extends VBean {
      private URL url;
      private URL m_codeBase; 
      private Image img;
    public void paint(Graphics g) {
      // draw the image
      g.drawImage(img, 0, 0, this);
    public void init(IHandler arg0) {
       super.init(arg0);
       // load image file
       img = loadImage("file:///c:/coyote.jpg");   
    public test()
        super();
       *  Load an image from JAR file, Client machine or Internet URL  *
      private Image loadImage(String imageName)
        URL imageURL = null;
        boolean loadSuccess = false;
        Image img = null ;
        //JAR
        imageURL = getClass().getResource(imageName);
        if (imageURL != null)
          try
            img = Toolkit.getDefaultToolkit().getImage(imageURL);
            loadSuccess = true;
            return img ;
          catch (Exception ilex)
            System.out.println("Error loading image from JAR: " + ilex.toString());
        else
          System.out.println("Unable to find " + imageName + " in JAR");
        //DOCBASE
        if (loadSuccess == false)
          System.out.println("Searching docbase for " + imageName);
          try
            if (imageName.toLowerCase().startsWith("http://")||imageName.toLowerCase().startsWith("https://"))
              imageURL = new URL(imageName);
            else if(imageName.toLowerCase().startsWith("file:"))
              imageURL = new URL(imageName);
            else
              imageURL = new URL(m_codeBase.getProtocol() + "://" + m_codeBase.getHost() + ":" + m_codeBase.getPort() + imageName);
            System.out.println("Constructed URL: " + imageURL.toString());
            try
              img = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              System.out.println("Image found: " + imageURL.toString());
              return img ;
            catch (Exception ilex)
              System.out.println("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            System.out.println("Error creating URL - " + urlex.toString());
        //CODEBASE
        if (loadSuccess == false)
          System.out.println("Searching codebase for " + imageName);
          try
            imageURL = new URL(m_codeBase, imageName);
            System.out.println("Constructed URL: " + imageURL.toString());
            try
              img = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              System.out.println("Image found: " + imageURL.toString());
              return img ;
            catch (Exception ilex)
                    System.out.println("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            System.out.println("Error creating URL - " + urlex.toString());
        if (loadSuccess == false)
          System.out.println("Error image " + imageName + " could not be located");
        return img ;
    }Francois

  • Can one add more than one photo layer to a draw image?

    I cannot seem to find a way to add more than one photo or photo layer to a Draw image, but the Draw page on Adobe seems to imply multiple photos can be added. How might I accomplish this? Thanks for your time.

    Unfortunately, Draw is currently limited to one photo layer, and only one photo within that layer.
    Hope that helps,
    Frank
    Draw Engineering

  • Looking for an app where i can draw images then text them?

    Looking for an app where I can draw images then text them?

    Just write Draw into the MAS searchbox in the upper right corner and you will be presented with a plethora of drawing/sketching apps of varying abilities and pricing.

  • Specification to Draw image on a page

    Can any one tell me exact Specification to draw image on a page.

    What don't you understand from the PDF Reference?
    You need an Image XObject and the Do operator in the content stream.
    Leonard

  • Problems drawing images form another class

    Ok as the title says I'm having trouble drawing images from a different class. I have a class that represents a plane and it has a draw' method that draws its .gif image.
    public void draw (Graphics g)
    g.drawImage(planepic , xPos, yPos, null)
    then in my main class in the paint method i have
    plane.draw(g);
    I think my problem is the null for my image observer. I tried using null as my image observer and i got a error saying i can't make a static reference to a non static method.
    I've done some research because i never really understood static but i still don't quite get it.
    Also when I use this as my image observer i get a error in my plane object.
    I also just tried passing and making a object for my main class and i still got the static error.
    Any help is appreciated and thanks in advance

    Ok as the title says I'm having trouble drawing
    images from a different class. I have a class that
    represents a plane and it has a draw' method that
    draws its .gif image.
    public void draw (Graphics g)
    g.drawImage(planepic , xPos, yPos, null)
    in my main class in the paint method i have
    plane.draw(g);
    I think my problem is the null for my image observer.
    I tried using null as my image observer and i got a
    error saying i can't make a static reference to a non
    static method. Use a minimal implementation of the ImageObserver to be sure.
    public class Plane implements ImageObserver
    public boolean imageUpdate(
    Image img,int infoFlags,int x,int y,int width,int height)
       switch(infoFlags)
          case ALLBITS:
                    return false;
          case SOMEBITS:
                    return true;
          default:
                return true;
    I've done some research because i never really
    understood static but i still don't quite get it.
    Also when I use this as my image observer i get a
    error in my plane object.
    I also just tried passing and making a object for my
    main class and i still got the static error.
    Any help is appreciated and thanks in advanceWhen you call draw(g) from your other class you hand it a Graphics context that you instantiated somewhere else ie: in another class. Without a more complete example it is really impossible to determine your issue for sure,
    but if I was to guess I would say you need to make sure that the Graphics context handed to the draw(Graphics) method was instantiated from a Component that was already visible. ie: Do a f
    Frame.createImage() from your parent frame after iyou have already called setVisible(true); In other words I suspect you are making and Image from some other Component that is not yet visible. That however is a guess so if not the issue post the rest of the code or at least a minimal implementation that demonstrates this.
    About static:
    static means the class/variable is the same throughout ALL classes of that type and if changed in one instance it will change and thus be the same for all instances.
    You CAN call static by referencing the base class Object without having to instantiate.
    ie:given
    public class SomeClass
    static String name;
    static String getName
       if(name == null)
          name = "DefaultName";
       return name;
    }Thus you could call..
      String name = SomeClass.getName();As opposed to
    SomeClass myClass = new SomeClass();
          myClass.getName();This can get you in trouble if you try to make a method that is static
    that then tries to reference non static variables.
    ie:
    public class SomeClass
    int x;
    static String name;
    SomeClass()
       x=0;
    static String getName
       if(name == null)
          name = "DefaultName";
       x++;
       return name;
    }In this case SomeClass.getName(); will throw and exception because it is trying to access[b] x  from a static context .
    Hope that clears that up for you; if not post a more complete example.
    Good Luck!
    (T)

  • Blast from the past: How do I draw image maps in Dreamweaver CC 2014?

    Need to update some old stuff, and can´t find where to draw image-maps on images.

    First, you need to be in Design View to get the image map tools to appear.
    Once there, the image map icons should show when you select an image. If they don't, you may have your Properties panel collapsed. In the bottom right corner of the Properties panel, there's a tiny triangle, click that to expand the panel to include the image map tools.

  • Converting an Image object to a BufferedImage object?

    I have a BufferedImage object, bi, which I want to resize, hence:
    Image image = bi.getScaledInstance(400, 300, Image.SCALE_DEFAULT);
    Next I want to encode the resized image to JPEG format. The problem is that inorder to use the JPEGImageEncoder.encode() method, I need to pass it a BufferedImage object. I have looked through the API and cant see a way of converting the Image object to a BufferedImage object.
    Can anyone shed some light on this problem?
    Any help will be much appreciated.

    I copied + pasted the code from:
    http://java.sun.com/docs/books/tutorial/2d/problems/ind
    x.html :-)
    So you propably could use :
    int width = 400;
    int height = 300;
    Image image = bi.getScaledInstance(width, height,
    Image.SCALE_DEFAULT);
    BufferedImage bi = new BufferedImage(width, height,
    BufferedImage.TYPE_INT_RGB);
    Graphics2D biContext = bi.createGraphics();
    biContext.drawImage(img, 0, 0, null);Greets
    PuceThis works fine; but has anybody else noticed this takes an unreasonable amount of time? How to get around this?

  • Graphics refuses to draw Images

    I was attempting to make an applet today, but for some reason, I can't draw Images. I had a little program going, but I decided to make this basic test applet to see if Images would draw at all.
    import java.awt.*;
    import java.applet.*;
    public class TestApplet extends Applet
         Image im;
         public void init()
              setSize(300, 400);
              im = getImage(getDocumentBase(), "Picture.GIF");
         public void start()
              repaint();
         public void paint(Graphics g)
              g.drawImage(im, 10, 10, this);
              g.drawString("I can draw a string", 10, 10);
         public void stop()
         public void destroy()
    }The string gets drawn fine, but the image just refuses to show up. Any idea why?
    Message was edited by:
    Guest42

    //  <applet code="TestApplet" width="300" height="400"></applet>
    import java.awt.*;
    import java.applet.*;
    public class TestApplet extends Applet
         Image im;
        public void init()
            setSize(300, 400);
            im = getImage(getDocumentBase(), "Picture.GIF");
            loadImage();
        private void loadImage()
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(im, 0);
            try
                tracker.waitForID(0);
            catch(InterruptedException ie)
                System.err.println("interrupt: " + ie.getMessage());
            int status = tracker.statusID(0, false);
            String results = "";
            if((status & MediaTracker.COMPLETE) == MediaTracker.COMPLETE)
                results += "COMPLETE";
            if((status & MediaTracker.ABORTED) == MediaTracker.ABORTED)
                results += "ABORTED";
            if((status & MediaTracker.ERRORED) == MediaTracker.ERRORED)
                results += "ERRORED";
            System.out.println("results = " + results);
        public void start()
    //        repaint();
        public void paint(Graphics g)
            g.drawImage(im, 10, 10, this);
            g.drawString("I can draw a string", 10, 10);
        public void stop()
        public void destroy()
    }

  • How to draw image in different dpi?

    I wonder is there any approach can be used to draw a image in different dpi, such as 144dpi, in a JPanel?
    'cause my image processed from other tools is not good, if I can draw image in a high dpi, then the image will looks much better, though the image becomes smaller.
    Note: no SCALE!

    I have a image which is 152dpi, then, how does the Widows draws this image? It looks much better than scale the 72dpi image to the same size.
    Really puzzled-_-                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • HT1414 how do you reset your password if you have forgotten it

    I am trying to restore my iphone3 everything ok till it asked for the password on my encryption i have forgotten it how can I restore my phones settings from the encrypted backup

  • Is the iTunes and App Store down? 7/21/12

    I've not been able to connect to the Apple App Store or iTunes store since yesterday 07/20/12. I've tried with my MacBook Air, iPad and iPhone and just keep getting the message that the device is not able to connect to the store and to check my netwo

  • [SOLVED] Iptables doesn't allow pacman -S(y) anymore...

    Hi there, First of all, sorry for my english . I've just configured my firewall, but now i can't get pacman working great. Nowatime I can't synchronise, and i can't install anything. So, I think that pacman use port number 80, but iam not sure. I did

  • How can I tell when an iTunes playlist was created?

    I like to note the date when I create playlists, but sometimes I forget. Is there any way to determine when one was created, either through iTunes or the OS?

  • APIM REST API - How to add an API with operations?

    When I issue a PUT to /apis/{aid} with import=true and contentType = application/json, I get an 400 BadRequest if the body contains operations.  Note that I'm not using WADL or Swagger format, and am building the JSON request body instead as per the