Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-01-2008, 04:55 AM
Member
 
Join Date: Apr 2008
Posts: 2
nuur is on a distinguished road
set coordinate to an image
hello javarians...

can any one guide me please... how I can set a coordinate on the background image so I can placed other image on top of that background image? like a collage?

hopefully a reply soon.. thanks in advanced !
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-01-2008, 06:13 AM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class Collage extends JPanel { BufferedImage top; BufferedImage bottom; Point loc = new Point(); public Collage(BufferedImage[] images) { top = images[0]; bottom = images[1]; } protected void paintComponent(Graphics g) { super.paintComponent(g); int x = (getWidth() - bottom.getWidth())/2; int y = (getHeight() - bottom.getHeight())/2; g.drawImage(bottom, x, y, this); g.drawImage(top, loc.x, loc.y, this); } private void save() { int w = getWidth(); int h = getHeight(); int type = BufferedImage.TYPE_INT_RGB; BufferedImage save = new BufferedImage(w, h, type); Graphics2D g2 = save.createGraphics(); paint(g2); g2.dispose(); try { ImageIO.write(save, "jpg", new File("collage.jpg")); } catch(IOException e) { System.out.println("write error: " + e.getMessage()); } ImageIcon icon = new ImageIcon(save); JOptionPane.showMessageDialog(this, icon, "save", -1); } private JPanel getSouth() { JButton button = new JButton("save"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { save(); } }); JPanel panel = new JPanel(); panel.add(button); return panel; } public static void main(String[] args) throws IOException { String[] ids = { "hawk", "blackBear" }; BufferedImage[] images = new BufferedImage[ids.length]; for(int j = 0; j < images.length; j++) { String path = "images/" + ids[j] + ".jpg"; images[j] = ImageIO.read(new File(path)); } Collage test = new Collage(images); test.addMouseListener(test.ml); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(test); f.add(test.getSouth(), "Last"); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { loc = e.getPoint(); repaint(); } }; }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-01-2008, 09:08 AM
Member
 
Join Date: Apr 2008
Posts: 2
nuur is on a distinguished road
thanks for the code..i`ll try to look after.. thanks again !
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
X&Y Coordinate Drawing on jPanel BHCluster Java 2D 2 03-27-2008 11:47 AM
Uploading image using JSP Java Tip Java Tips 0 01-11-2008 10:16 AM
Converting multiple banded image into single banded image... Image enhancement archanajathan Advanced Java 0 01-08-2008 06:29 PM
how to set an image size valery New To Java 1 08-06-2007 09:27 PM
Image Verification peiceonly Java Servlet 1 04-27-2007 05:50 PM


All times are GMT +3. The time now is 02:31 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org