fixed buggy loop
added save file dialog for the first captured image, subsequent images automatically get the same name with an ascending index number