private void writeImage() throws IOException {
        int pImage[] = new int[height * height];
        for (int row = 0, count = 0; row < height; row++) {
            for (int col = 0; col < width; col++) {
                pImage[count] = rgbArray[row][col];
                count++;
            }
        }
        img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        img.setRGB(0, 0, width, height, pImage, 0, width);
        ImageIO.write(img, "bmp", new FileOutputStream("RESULT.bmp"));  // save image
    }