public ImagesIterator(File dir) throws IOException {
	if (!dir.isDirectory()) {
	    throw new IOException(dir + " is not a directory!");
	}

	String[] imageFilenames = dir.list(new FilenameFilter() {
	    @Override
	    public boolean accept(File dir, String name) {
		if (name.length() > 4) {
		    String fileExtension = name.substring(name.length() - 4, name.length());
		    return ".jpg".equalsIgnoreCase(fileExtension)
			    || ".png".equalsIgnoreCase(fileExtension);
		}
		return false;
	    }
	});

	List<File> imageFiles = new ArrayList<>();
	for (String imageFile : imageFilenames) {
	    imageFiles.add(new File(dir, imageFile));
	}

	imageIterator = imageFiles.iterator();
    }