//Store the two input images as buffered images
public void loadImages() throws FileNotFoundException, IOException{
barcodeImage = getImage("8DigitsGrey.jpg");
}
//Read the images in
public BufferedImage getImage(String filename) throws FileNotFoundException, IOException {
File file = new File(filename);
if(!file.exists())
throw new FileNotFoundException(filename);
barcodeImage = ImageIO.read(file);
return barcodeImage;
}
//Create a 2Darray of pixels of the image
public void buildArray() {
int width = barcodeImage.getWidth();
int height = barcodeImage.getHeight();
pixelData = new int[width][height];
for(int i=0; i<width; i++) {
for(int j=0; j<height; j++) {
pixelData[i][j] = (barcodeImage.getRGB(i,j))&255; //getRGB returns the RGB value of the current pixel
}
}
}
private static void createAndShowGUI() throws FileNotFoundException, IOException {
JFrame frame = new JFrame("Image"); // Create the container
//Quit the application when this frame is closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and add the content
Barcode panel = new Barcode();
frame.add(panel);
// Display the window
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
frame.setVisible(true); // Now the frame will appear on screen
}
public Barcode() throws FileNotFoundException, IOException {
loadImages();
buildArray();
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new BorderLayout());
picLabel = new JLabel(new ImageIcon(getImage("8Digits.jpg")));
imagePanel.add("Center", picLabel);
setLayout(new BorderLayout());
setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
add("Center", imagePanel);
drawSquare();
}
//Draws a line onto the image
public void drawSquare(){
barcodeImage.setRGB( 319, barcodeT, RED);
barcodeImage.setRGB( 320, barcodeT, RED);
barcodeImage.setRGB( 321, barcodeT, RED);
}
public static void main(String[] args) throws FileNotFoundException, IOException {
createAndShowGUI();
}