Can I create image in Canvas?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   tiffany_angel
Posted On:   Friday, July 1, 2005 04:42 AM

Hi all,

I would like to know whether I can display an image(gif/jpg) in canvas? How could I achive that?

Thank you

Re: Can I create image in Canvas?

Posted By:   shay_te  
Posted On:   Thursday, September 29, 2005 10:07 AM

public class ImageViewer extends Canvas{

private Image img = null;



public ImageViewer (File file){

img = getToolkit().createImage(file.getAbsolutePath());

}

public void paint(Graphics g){

if(img != null){

g.drawImage(img ,0,0,this);

}

}

}

Re: Can I create image in Canvas?

Posted By:   Almagest_FUTT  
Posted On:   Friday, July 1, 2005 05:24 AM

Sure. You have to obtain an instance of java.awt.Image (e.g using Toolkit.createImage(byte[]) or javax.swing.ImageIcon.getImage()) and then draw it in the (overridden) paint(Graphics) method of your Canvas.
About | Sitemap | Contact