oneslime.net Forum Index oneslime.net
Slime talk
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to handle images in java?

 
Post new topic   Reply to topic    oneslime.net Forum Index -> Programming
View previous topic :: View next topic  
Author Message
serafin
Inferior Human Controlled Slime


Joined: 04 Jun 2006
Posts: 8
Location: Mexico

PostPosted: Sun Jun 04, 2006 2:43 am    Post subject: How to handle images in java? Reply with quote

I want to know which is the easiest way to use images in a java application and modify it (like drawing lines in the image)?

Can anyone help me?

Thanks
Back to top
View user's profile Send private message
wedgey
Site Admin


Joined: 01 Mar 2006
Posts: 207
Location: three quarters of a mile from the surface of the sun

PostPosted: Sun Jun 04, 2006 11:51 am    Post subject: Reply with quote

You can load images from a file using the following code:
Code:
      try
      {
         BufferedImage im = ImageIO.read(new File(yourfilename));
         getGraphics().drawImage(im,0,0,null);
      } catch (IOException _ex) {
         _ex.printStackTrace();
      }

ImageIO is a useful class in the javax.imageio package - see http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageIO.html
BufferedImage is a class in the java.awt.image package.

To draw lines on an image, there's some sample code at http://oneslime.net/wiki/Tutorial_2_-_Handling_mouse_input
You should change the line
Code:
Graphics g = getGraphics();

to
Code:
Graphics g = image.getGraphics();

where image is your image.
Back to top
View user's profile Send private message
serafin
Inferior Human Controlled Slime


Joined: 04 Jun 2006
Posts: 8
Location: Mexico

PostPosted: Tue Jun 06, 2006 2:59 am    Post subject: Reply with quote

Thanks
_________________
No signature available
Back to top
View user's profile Send private message
juston33
Inferior Human Controlled Slime


Joined: 26 Mar 2015
Posts: 1

PostPosted: Thu Mar 26, 2015 8:43 pm    Post subject: Reply with quote

To draw lines on an image, there's some sample code at ther.
_________________
http://www.test-king.com/learn-language/IELTS.htm
http://www.test-king.com/learn-language/TOEFL.htm
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    oneslime.net Forum Index -> Programming All times are GMT + 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group