The Chinese philosopher and scientist Mozi may have been the first person to write about a camera obscura, about 400 BC - anyway, Mozi's is the first one we know about. As Mozi said, "The image (or shadow) being inverted depends on there being an aperture at the cross-over and the image (or shadow) being distant. The explanation lies in the aperture."
Today we call Mozi's invention a "camera obscura". The words "camera obscura" are Latin for "dark room", and a camera obscura is the very earliest, simplest kind of camera. (Notice how we still call it a camera!)
If you take a closed box, so it's dark inside, and make a small hole in one side of it, light will come in and form an upside-down image of things outside the box.
You can build your own camera obscura in a few minutes. Take any closed box - a shoebox, or any cardboard box - and tape over all the cracks so it is completely dark inside. Cut a square out of one side, and tape a Kleenex over the hole. On the opposite side of the box, cut a small square out and tape a piece of aluminum foil over it. Use a pin to poke a tiny hole in the middle of the aluminum foil - no bigger around than a pencil lead. Point the pin-hole at a bright light bulb from a couple of inches away and look at the tissue screen with a heavy blanket over your head to make it as dark as possible. You should see a picture of the light bulb projected upside down on your screen.
Once you've got that working, try to get your camera working outside in sunlight - then you can see the scenery around you.
Mozi's students kept on experimenting with the camera obscura, and soon people further west like Aristotle heard about it too. In China, people followed Confucius rather than Mozi and they gradually forgot Mozi's experiments. By 850 AD, when Duan Chengshi used a camera obscura, he didn't understand why the image was upside-down. But then about 1050 AD, during the Song Dynasty, Chinese scientists seem to have read a translation of Ibn al-Haytham's Optics. Shen Gua was able to explain the camera obscura in his book, The Dream Pool Essays. Shen Gua also knew why curved mirrors - which he calls "burning-mirrors" - turn an image upside-down. He says,
"This is because there is a focal point in the middle (i.e., between the object and the mirror)...It is like the pattern made by an oar moved by someone in a boat against an oarlock [two cones, touching at their top points]. We can see it happening in the following example: when a bird flies in the air, its shadow moves along the ground in the same direction. But if its image is collected (like a belt being tightened) through a small hole in a window [a camera obscura], then the shadow moves in the direction opposite to that of the bird. The bird moves to the east while the shadow moves to the west, and vice versa. Take another example. The image of a pagoda, passing through the hole or small window, is inverted after being 'collected'. This is the same principle as the burning-mirror. Such a mirror has a concave surface, and reflects a finger to give an upright image if the object is very near, but if the finger moves farther and farther away it reaches a point where the image disappears and after that the image appears inverted. Thus the point where the image disappears [in a convex lens] is like the pinhole of the window [in a camera obscura]. So also the oar is fixed at the oarlock somewhere in the middle, making a sort of waist, and when the handle of the oar is up, the paddle is always down in the water, and vice versa. Since the surface of the burning-mirror is concave, when it faces the sun it collects all the light and brings it to a point one or two inches away from the mirror's surface, as small as a hempseed. That's where things catch fire: where the waist is smallest."
Chinese scientists like Shen Gua seem to have read al-Haytham's Optics before Europeans like Roger Bacon did. Just after Bacon, in the 1200s AD, the Chinese Daoist scientist Zhao Youqin also built on Shen Gua's work. Zhao Youqin did experiments with a camera obscura to find out the geometrical relationship between how far the image was from the pinhole and how bright it was.