i am trying to load a jpg image on a canvas where the Line2D line1 is being drawn at. I wanted to overlay the image under the line because i am trying to do a symmetry math question online.
I keep getting the exception error file not found but i have placed my image in the main directory in the java file itself.
Any one can help??
public SliderControlPaintLine() {
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new GridLayout(2,2));
getContentPane().add(controlPanel, BorderLayout.NORTH);
JLabel label1 = new JLabel("Translate(dx,dy): ");
JLabel label2 = new JLabel("Rotate(Theta,ox,oy): ");
JLabel label3 = new JLabel("Scale(sx,sy)x10E-2:");
controlPanel.add(label1);
slider1 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);
slider2 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50);
controlPanel.add(label2);
slider3 = createSlider(controlPanel, JSlider.HORIZONTAL, 0, 360, 0, 90, 45);
getContentPane().add(canvas);
try {
image = ImageIO.read(new FileInputStream("symmetry.jpg"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setSize(800,700);
setVisible(true);
}
I am showing where i declared and initialized the ImageIO.
class DrawingCanvas extends Canvas {
public DrawingCanvas() {
setSize(300, 300);
}
public void paint(Graphics g) {
super.paint(g);
g.drawImage(image, 0, 0, this);
Graphics2D g2D = (Graphics2D) g;
g2D.translate(transX, transY);
g2D.rotate(rotateTheta, rotateX, rotateY);
g2D.scale(scaleX, scaleY);
BasicStroke stroke = new BasicStroke(width);
g2D.setStroke(stroke);
Line2D line1 = new Line2D.Float(100f, 200f, 500f, 200f);
g2D.draw(line1);
}
}