请牛人指教
我现在做个东西,需要把一张图片加载到内存中,然后在显示出来,然后用鼠标点击图片上的点,能获取图片上的点的三维坐标,请提供一个具体的思路,说的详细点!多谢了,我一点图片处理的经验都没有!请大神说些点!
------解决方案--------------------显示图片
------解决方案--------------------package test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class AppPanel extends JPanel {
// variables and components==========================
private JPanel imageBox;
private JPanel toolPane;
private JLabel counterLabel;
private int counter;
private boolean showWholeImage;
private JButton selectButton;
private JButton breakButton;
private JButton viewImageButton;
private Image[] images;
private Image wholeImage;
private JFileChooser chooser;
// constructor=============================
public AppPanel() {
// initial variables
chooser = new JFileChooser();
images = new BufferedImage[24];
wholeImage = null;
showWholeImage = true;
counter = 0;
setLayout(new BorderLayout());
// initial components
imageBox = new JPanel();
imageBox.setBackground(Color.GRAY);
toolPane = new JPanel();
counterLabel = new JLabel("操作次数:" + counter);
viewImageButton = new JButton("显示原图");
selectButton = new JButton("选择图片");
final Component self = this;
final JLabel lable = new JLabel();
selectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(self)) {
try {
wholeImage = ImageIO.read(chooser.getSelectedFile());
showWholeImage = true;
lable.setIcon(new ImageIcon(wholeImage));
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "打开文件失败");
}
}
}
});
breakButton = new JButton("打乱图片");
toolPane.add(counterLabel);
toolPane.add(selectButton);
toolPane.add(breakButton);
toolPane.add(viewImageButton);
add(toolPane, BorderLayout.SOUTH);
add(lable);
img =Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("test/a.jpg"));
lable.setIcon(new ImageIcon(img));
}
private Image img;
public static void main(String[]args) {
JFrame frm = new JFrame("test");
AppPanel appPanel = new AppPanel();
frm.getContentPane().add(appPanel);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(600,400);
frm.setVisible(true);
}
}
------解决方案--------------------
鼠标移到
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MoveMessageDemo extends JFrame {
public MoveMessageDemo() {
MovableMessagePanel p = new MovableMessagePanel("welcome to java");
p.setFont(new Font("Serif", Font.BOLD, 24));
setLayout(new BorderLayout());
add(p);
}