Cannot Draw images to Canvas

Hey guys i am having trouble drawing my images to my canvas can anyone provide me with some advice id really appreciate it. Thanks in advance. here is my code so far. I also posted this question on another forum but no response yet.
package pgame;
import javax.swing.*;
import java.awt.*;
public class PGame extends JPanel {
     public PGame() {
     add(new PBoard());
    public static void main(String[] args){
    JFrame frame = new JFrame("Game");
    frame.setContentPane(new PBoard());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setSize(240,430);
    frame.setResizable(false);
    frame.setVisible(true);
package pgame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*; 
import javax.swing.event.*;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
public class PBoard extends JPanel{
Canvas canvas;
final int height = 12;
final int width = 6;
final int canvas_height = height*32;
final int canvas_width = width*32;
private BufferedImage bufferedImage;
Image image[];
  public PBoard() {
      super();
     image = new Image[4];
     image[0] = Toolkit.getDefaultToolkit().getImage("image1.png");
     image[1] = Toolkit.getDefaultToolkit().getImage("image2.png");
     image[2] = Toolkit.getDefaultToolkit().getImage("image3.png");
     image[3] = Toolkit.getDefaultToolkit().getImage("image4.png");
     canvas = new Canvas();
     canvas.setBounds(20,20,240,430);
     canvas.setSize(canvas_width,canvas_height);
     canvas.setBackground(Color.BLACK);
     add(canvas);
    public void paintComponent(Graphics g){
    super.paintComponent(g); 
    g.setColor(Color.RED);
    g.drawRect(0,0,233,397); // Draw a border
    g.drawImage(image[0],0,0,this);
}

Riz01 wrote:
I have no real reason for it i just did it i was thinking of creating a double buffer and drawing my image through that onto my canvas.A very bad reason for doing this. Swing is double buffered automatically. When you use a Canvas, you lose this. Also, when you combine Swing and AWT components in the same GUI, strange bugs can occur. Please don't do this unless you know why you're doing it, and how to avoid the bugs that it will cause.

Similar Messages

  • Image on canvas prob...

    Is there any way to know that whether an image is present at particular location on canvas or not?
    Actually, i have written a code that draws image on canvas and moving it randomly. I have to keep checking how many times the image passes through a rect area at particular location.....
    ...........Its a part of my project ..Plz help me out!

    Make a Rectangle with width and height equal to the moving image dimensions. Move/position the rectangle from your event code and draw the image at its origin (x,y). Then it is a simple matter to check for intersection between this moving rectangle and the target rectangle.

  • Error draw an image on canvas

    Hello! In this code, the drawImage method is returning false. If the same code is run as a desktop application using the main method the error does not happen.
    Who knows why?
    public class AppJavaTV implements Xlet{
        private XletContext context;
        private Container container;
        private SCanvas canvas;
        public void initXlet(XletContext arg0) throws XletStateChangeException {
            context = arg0;
            container = TVContainer.getRootContainer(arg0);
            canvas = new SCanvas();
            canvas.setLocation(0, 0);
            canvas.setSize(container.getSize());
            canvas.setBackground(Color.white);
            container.add(canvas);
            container.setVisible(true);
        public void startXlet() throws XletStateChangeException {}
        public void pauseXlet() {}
        public void destroyXlet(boolean arg0) throws XletStateChangeException {}
        public static void main(String argv[]) {
            Frame frame = new Frame();
            frame.setLayout(new BorderLayout());
            frame.add("Center", new SCanvas());
            frame.resize(400, 400);
            frame.show();
    public class SCanvas extends Canvas{
        Image img = null;
        public SCanvas(){
            MediaTracker media = new MediaTracker(this);
            img = Toolkit.getDefaultToolkit().createImage("/Image.jpg");
            media.addImage(img, 0);
            try {
                media.waitForID(0);
            } catch (Exception e) {}
        @Override
        public void paint(Graphics graphics){
            graphics.setColor(Color.blue);
            graphics.drawRect(0, 0, 50, 50);
            graphics.setColor(Color.black);
            if(!graphics.drawImage(img, 200, 200, this))
                graphics.drawString("Error on draw image", 200, 200);
    }

    That is because you are using Canvas and Container objects. That objects are not used on the DTV environment. You should use the ones adapted to it, the ones contained in org.havi.ui, like HContainer, HScreen...
    Remember tha java.awt is not used (except for some classes) and the equivalent elements are under org.havi.ui

  • Place image on canvas

    Hi.
    I am trying to place image on canvas.
    However the image doesn't show!!!!!!!!!!!!! :(
    no error and compiles well....
    private void AddTile(String image, int startx, int starty, int endx, int endy)
    try{
    tiles = ImageIO.read(new File(image));
    catch(Exception e)
    System.out.println("Image not Found");
    Graphics2D a =(Graphics2D)tiles.getGraphics();
    a.drawImage(tiles, 20,20,20,20,TileCanvas);
    if the above function is called the image should be placed on canvas right?
    TileCanvas is a canvas, and tiles is BufferedImage.
    just in case I'll put my source code followed by this
    * MapEditor.java
    * Created on 2006�� 7�� 20�� (��), ���� 11:48
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.imageio.*;
    import java.io.*;
    * @author SeiKwon
    public class EditorComponent extends javax.swing.JFrame
    private java.awt.Button AddTile;
    private java.awt.Button DeleteTile;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JMenuItem LoadFile;
    private javax.swing.JPanel ManageTilePanel;
    private java.awt.Canvas MapCanvas;
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JMenuItem SaveFile;
    private javax.swing.JScrollPane ShowMapScroll;
    private java.awt.Canvas TileCanvas;
    private javax.swing.JScrollPane TileScroll;
    private BufferedImage tiles;
    private int tilecount = 0;
    /** Creates new form MapEditor */
    public EditorComponent()
    initComponents();
    AddTile("test.jpg", 0, 0, 10, 10);
    private void initComponents()
    ManageTilePanel = new javax.swing.JPanel();
    TileScroll = new javax.swing.JScrollPane();
    TileCanvas = new java.awt.Canvas();
    AddTile = new java.awt.Button();
    DeleteTile = new java.awt.Button();
    ShowMapScroll = new javax.swing.JScrollPane();
    MapCanvas = new java.awt.Canvas();
    MenuBar = new javax.swing.JMenuBar();
    FileMenu = new javax.swing.JMenu();
    SaveFile = new javax.swing.JMenuItem();
    LoadFile = new javax.swing.JMenuItem();
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    ManageTilePanel.setLayout(null);
    ManageTilePanel.setBorder(new javax.swing.border.TitledBorder("Tiles"));
    TileCanvas.setBackground(new java.awt.Color(255, 255, 255));
    TileScroll.setViewportView(TileCanvas);
    ManageTilePanel.add(TileScroll);
    TileScroll.setBounds(10, 22, 100, 230);
    AddTile.setLabel("Add");
    ManageTilePanel.add(AddTile);
    AddTile.setBounds(10, 260, 50, 26);
    DeleteTile.setLabel("Delete");
    ManageTilePanel.add(DeleteTile);
    DeleteTile.setBounds(60, 260, 50, 26);
    getContentPane().add(ManageTilePanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 10, 119, 290));
    ManageTilePanel.getAccessibleContext().setAccessibleName("TilesPanel");
    MapCanvas.setBackground(new java.awt.Color(255, 255, 255));
    MapCanvas.addMouseListener(new java.awt.event.MouseAdapter()
    public void mouseEntered(java.awt.event.MouseEvent evt)
    MapCanvasMouseEntered(evt);
    ShowMapScroll.setViewportView(MapCanvas);
    getContentPane().add(ShowMapScroll, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 10, 290, 290));
    FileMenu.setText("File");
    FileMenu.setContentAreaFilled(false);
    SaveFile.setIcon(new javax.swing.ImageIcon("D:\\java\\MapEditor\\Image\\Save16.gif"));
    SaveFile.setText("Save");
    SaveFile.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(java.awt.event.ActionEvent evt)
    SaveFileActionPerformed(evt);
    FileMenu.add(SaveFile);
    LoadFile.setIcon(new javax.swing.ImageIcon("D:\\java\\MapEditor\\Image\\Open16.gif"));
    LoadFile.setText("Load");
    LoadFile.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(java.awt.event.ActionEvent evt)
    LoadFileActionPerformed(evt);
    FileMenu.add(LoadFile);
    MenuBar.add(FileMenu);
    setJMenuBar(MenuBar);
    pack();
    private void MapCanvasMouseEntered(java.awt.event.MouseEvent evt)
    Cursor cursorshape = MapCanvas.getCursor();
    MapCanvas.setCursor(cursorshape.getPredefinedCursor(CROSSHAIR_CURSOR));
    private void AddTile(String image, int startx, int starty, int endx, int endy)
    try{
    tiles = ImageIO.read(new File(image));
    catch(Exception e)
    System.out.println("Image not Found");
    Graphics2D a =(Graphics2D)tiles.getGraphics();
    a.drawImage(tiles, 20,20,20,20,TileCanvas);
    private void LoadFileActionPerformed(java.awt.event.ActionEvent evt)
    FileDialog fd = new FileDialog(this, "Open", FileDialog.LOAD);
    //fd.setFile("*.map");
    fd.setDirectory(".");
    fd.setVisible(true);
    String filename = fd.getFile();
    System.out.println(filename);
    private void SaveFileActionPerformed(java.awt.event.ActionEvent evt)
    FileDialog fd = new FileDialog(this, "Save", FileDialog.SAVE);
    //fd.setFile("*.map");
    //fd.setFilenameFilter("*.map"); // HOW TO USE?????????????
    fd.setDirectory(".");
    fd.setVisible(true);
    String filename = fd.getFile();
    System.out.println(filename);
    public static void main(String args[])
    java.awt.EventQueue.invokeLater(new Runnable()
    public void run()
    new EditorComponent().setVisible(true);
    }

    You have at least two problems.
    1) You are mixing AWT and Swing. Instead of using a Canvas you should use either a JComponent or a JPanel.
    2) In Swing, drawing such are you are doing should be done within the paintComponent(Graphics g) method using the Graphics provided as an argument to the method.
    P.S. I can't test you code because for some reason you feal the need to use a NetBeans specific layout manager.

  • 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

  • Displaying images in canvas one after another

    Hi all,
    I have a problem displaying images in canvas one after another. I am using for loop and when i run the application, all images run back in the and only finally only the last image gets displayed in the emulator. I also used thread.sleep(). But it din't work.
    Here is my code:
    // A canvas that illustrates image drawing
    class DrawImageCanvas extends Canvas
    Image image;
    public void paint(Graphics g)
    int width = getWidth();
    int height = getHeight();
    g.setColor(0);
    g.fillRect(0, 0, width, height);
    String images[]={"paint_2.PNG","radha.PNG","cute.png","design.png","flowers.png"};
    for(int i=0;i<images.length;i++)
    image = null;
    System.out.println("/"+images);
         try
         image = Image.createImage("/"+images[i]);
    catch (IOException ex)
    System.out.println(ex);
    g.setColor(0xffffff);
    g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
    return;
    if (image != null)
    g.drawImage(image, width/2, height/2, Graphics.VCENTER | Graphics.HCENTER);
    try
    Thread.sleep(5000);
    catch(Exception ex)
         System.out.println("the exception is.."+ex);
    Help me and Thanks in advance.

    See the code below : prefer the use of a Timer and a TimerTask instead of Thread.sleep().
    showNotify (from Canvas) is used to launch the timer.
    import java.io.IOException;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    public class DrawImage extends Canvas {
        Image image;
        String images[] = {"img1.png", "img2.png", "img3.png", "img4.png", "img5.png",
                            "img6.png", "img7.png"};
        Image[] tabImage;
        int imageCounter = 0;
        public DrawImage(){
            try {
                tabImage = new Image[images.length];
                for (int i = 0; i < images.length; i++)
                    tabImage[i] = Image.createImage("/" + images);
    } catch (IOException ex) {
    ex.printStackTrace();
    public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    g.setColor(0);
    g.fillRect(0, 0, width, height);
    image = tabImage[imageCounter];
    if (image != null)
    g.drawImage(image, width / 2, height / 2, Graphics.VCENTER | Graphics.HCENTER);
    else{
    System.out.println("null");
    g.setColor(0xffffff);
    g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
    protected void showNotify(){
    Timer t = new Timer();
    t.schedule(new PhotoSwitcher(), 5000, 5000);
    private class PhotoSwitcher extends TimerTask{
    public void run() {
    if (imageCounter < images.length - 1)
    imageCounter++;
    else
    imageCounter = 0;
    repaint();
    I hope this will help you !
    fetchy.
    Edited by: fetchy on 14 ao�t 2008 09:48                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Cannot open image in CS5?

    I am a Newbie to PS,  Running PS 5 on Windows 7,  I'm trying to bring up PS using the edit in command in Lightroom,  PS does comes up and the photo number comes up in the document tab, I see all the layers but the image is not visible. If I shut down PS and restart and the select open recent, the samee thing happens,  Thanks for any assistance

    Thanks Neil,  I did download the latest video driver and everything seems to work fine.  I do have to reload the driver of my NEC monitor.  Thanks again.  Lee Smith
    Date: Fri, 2 Dec 2011 13:41:17 -0700
    From: [email protected]
    To: [email protected]
    Subject: Cannot open image in CS5?
        Re: Cannot open image in CS5?
        created by Noel Carboni in Photoshop Windows - View the full discussion
    Sounds like one of many manifestations of a display driver bug... If going into Edit - Preferences - Performance, disabling OpenGL Drawing, then closing and restarting Photoshop changes the behavior, then you should visit the web site of the maker of your video card, download/install the latest display driver that matches your hardware and OS, re-enable OpenGL Drawing (making sure to restart Photoshop), and test again. Display driver updates fix many problems. -Noel
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4060242#4060242
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4060242#4060242. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Windows by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Clear image on canvas

    How to clear the image on canvas? I have a big image span the whole screen and I want to put another smaller image now. There is no "clear" method to be called! What I can do is to draw a rectangle. Any suggestion?
    Thanks!

    The following should clear your screen.
      // Clear the whole screen.
      g.setColor(255, 255, 255);
      g.fillRect(0, 0, getWidth(), getHeight());

  • Right click top bar to open Image Size/Canvas Size/Info?

    I've just upgraded from PS 5 to PS CC. In previous versions I was able to just right click on the top image bar to bring up a dialog box allowing me to access the Image Size, Canvas Size, Image Info, etc... That does not seem to be the case with PS CC, or am I missing a prefence setting that will allow this?
    Thanks!

    I tried your suggestion but still cannot access that info by right-clicking the bar. I've gone through my preference settings, primarily under the Interface section and enabled and disabled several options but still no luck. It's just habit from many years use and nice to be able to access several common settings I might adjust.
    The keyboard shortcuts are fine also, but again habit and if my hand is already on the mouse it's just...or was just a simple click. (Me being lazy)
    Thanks for the help and suggestions. If anyone else a suggestion, great!

  • Cannot delete images from LR 5

    First, my setup:
    LR 5.3
    New 2013 iMac with 3T fusion drive
    OS X Mavericks
    I migrated all of my apps, files, etc from a 2007 iMac, following Apple's procedure. To take advantage of the speed of the fusion drive, I moved my image files from a La Cie external drive to the iMac's fusion drive. (Yes, I am backed up, triply backed up with both external backup drives and cloud backup.) There were a few hiccups, but I straightened them out and now can access every one of my images, process, etc.
    But...since the migration and importation to the iMac internal fusion drive, I cannot delete images. When I'm sorting, I use the X key to mark images for deletion. Then, when I use the standard cmd-delete key combination, I get the standard window offering me the option of just removing the image from the catalog or deleting it from the disk. When I select the latter (since I don't want rejected images clogging my hard drive), a new window appears: The file named "___" could not be moved to the trash folder."
    The problem occurs only since the migration and moving of the images to the new drive.
    I have tried numerous fixes suggest in various forums—create a new folder, then delete it to create a channel for LR; check permissions; repair permissions; run various commands through terminal. It's maddening because I sometimes reject a few hundred images at a time, and there's simply no reason to retain them on my drive. Any help will be much appreciated and rewarded with a dram of virtual single-malt scotch.
    D

    You're right, Suzanne, I had...or so I thought. I had checked at too high a level in the folder hierarchy. When I drilled down, I found the last two levels of folders didn't even have me listed as an owner. Odd. What I found, to my delight, was that I could change permissions on the master image folder, then instruct that those changes be applied to all folders within the master folder. Solved the whole problem.
    So Suzanne, Geoff, even though neither of you directly provided the solution, your answers got me to check a couple of things that turned up the problem and the solution. So thanks!
    D

  • Using Firefox to access facebook chat Button or online friiend chat button generates a Black screen with CANNOT LOAD IMAGES and no chat window opens.

    This does not happen in other browsers and it happens on a variety of computers I have access to and would seem to be a common problem but I can find no identical cases in my searches of
    Firefox , Facebook or windows help or Google search. My home machine is only a P2 with WINXPCORP but works fine and I have done all updates but still have this continuing problem every time I try to use Firefox
    to access Facebook chat but it does not happen with IE or chrome
    The response to clicking on chat button or friend chat is a black screen with small center square box with blue title bar that says
    '' VIEW IMAGE FULL SCREEN - (42) FACEBOOK X""
    center of box is ""! "" mark in yellow triangle and wording
    "" CANNOT LOAD IMAGES ''' OK
    clicking on OK returns to facebook page but no chat opens.
    Some times |VERY RARLEY if as the page loades you click on
    chat button with 1/2 second of it appearing chat will open.

    Hi,
    Please also see [https://support.mozilla.org/en-US/kb/Problems%20using%20Facebook%20in%20Firefox this.]

  • 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

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

  • OutOf Memory Error while saving image of canvas

    Hi,
    I am facing a weired problem while saving the image of the graphics in Canvas. It's giving me OutOfMemory error. Here is snippet of code:
    if(cmd.equals(C.ACTION_SAVE)){
                try {
                    FileDialog fd = new FileDialog(frame, "Save ProcessInstance as JPEG", FileDialog.SAVE);
                    fd.setFile(processInstance.getProcessDefinition().getName() +processInstance.getProcessOwner() +processInstance.getProcessOwnerId() +".jpeg");
                    fd.show();
                    String name = fd.getDirectory()+fd.getFile();
                        int w = canvas.getWidth(), h = canvas.getHeight();
                        BufferedImage image = new BufferedImage(w, h,
                                BufferedImage.TYPE_INT_RGB);
                        Graphics2D g2 = image.createGraphics();
                        canvas.paint(g2);
                        g2.dispose();
                        ImageIO.write(image, "jpeg", new File(name));
                    } catch (IOException e) {
                        System.err.println(e);
                    }

    Hi,
    I tried to run garbage collector for the same and now its working fine. I want to know is there any drawback of using this approach. I am new to java and waiting for ur expert comments. I added following lines in the above code just below ImageIO.write(image, "jpeg", new File(name));:
             image = null;
                        Runtime r = Runtime.getRuntime();
                        r.gc();

  • Cannot read image file in oracle 10g forms, getting error frm-47100

    I'm unable to read the image from the file location. But If I do re-save via MS-Paint the same image then I'm able to load successfully. I want to load image directly instead of re-save.  Error getting like "frm-47100 Cannot read image file".
    Need your co-operation to solve this issue.
    Thanks in advance!
    declare
      tiff_image_dir varchar2(80):=('D:\IMAGE\');
      photo_filename varchar2(80);
    begin
      photo_filename:=tiff_image_dir||:IMAGE_NO||'.JPG';
      if :image_no is null then
      :Image_no :=:UID_NO;
      end if;
      read_image_file(photo_filename,'JPG','image');
      WRITE_IMAGE_FILE('output.tif','TIFF','g_image_info.image',maximize_compression,original_depth)
    end;

    Hi Sindhu,
    By default any operating system file extension starts after the dot. So in this case when it says 2 dots it will think there is something wrong.
    RajeshALex

Maybe you are looking for

  • Document browser - table

    Hi, In which table the linkage between folder and DIR is kept for document browser. Thanks. Anirudh,

  • Concurrent calling of Host function

    Hi all, I had using HOST() function in my form's library to sent label printing command to printer, it work ok when only 1 client is print label, but when there is concurrent client calling printing label function, one of the label not success to pri

  • Adobe for Palm

    I installed adobe reader on my palm lifedrive, and I can read ebooks in PDF now.  Because the PDF is DRM protected, I had to go through using Adobe 7.0 on my desktop, go to digital editions, send to mobile, which then goes through steps to "prepare"

  • My Photoshop CS6 is not responding.

    My Photoshop CS6 is not responding when opening. What should I do. thanks.

  • Xonar DG sound card headphone amplifier not working

    Hi, I have an Asus Xonar DG sound card. The sound is working fine, however it is very quiet. It seems that the headphone amplifier is not working - or, I cannot find a way to set the impedance. I have alsa running and tried messing with alsamixer set