What I have implemented till now in java is ask the user to upload an image from the directory. My next step is that when the image is loaded a grid is placed above that image just for visual purpose so that the image gets divided in a, say 10 x 10 grids. How do I implement this stuff? Here's what I have implemented till now.
JFileChooser choose=new JFileChooser();
choose.showOpenDialog(null);
File f=choose.getSelectedFile();
String filename=f.getAbsolutePath();
path.setText(filename);
BufferedImage img;
try {
img=ImageIO.read(f);
Image dimg = img.getScaledInstance(500,500,Image.SCALE_SMOOTH);
ImageIcon imageIcon = new ImageIcon(dimg);
image_label.setIcon(imageIcon);
}
catch(Exception e) {
System.out.println(e);
}
paint the image in a panel
Then based on the the number of cells you want, say 10x10, just draw 100 cells (
drawRect()
) over the image. Something likeI haven't test it, but the basic concept is there. You may also want to use variables (a constant probably) for the 10.
UPDATE 1
You can see the precision's a little off because I used
int
, but you can use doubles and draw by usingGrapchics2D
Rectangle2D.Double
. I'm too lazy to change itUPDATE 2
WithJLabel