I am making a video game where the world will be ~30000x10000 pixels. I want the whole world to be a single .png file. Keeping the whole world loaded is computationally expensive, so I would like to load only the part of the .png file around the player. How can I load part of a .png file in a given range?
Asked
Active
Viewed 49 times
0
-
If the world isn't going to be all loaded at once, why saving it to a single file? Why not splitting it into a number (100) of smaller files, which can be easily loaded on demand (depending on character's position)? – CristiFati Oct 15 '22 at 08:21
-
I might end up doing that! I know that type of chunking is common. Still, I want to know if there's a way to load only part of a .png and how that solution might impact how fast my game runs. – Kayla Oct 15 '22 at 08:27
-
Most libraries load images in their entirety. `vips` is able to efficiently load a subset of an image. TIFFs have the concept of strips and tiles which can make it even more efficient to extract subsets or regions. – Mark Setchell Oct 15 '22 at 08:32
-
Using `cv2` its easy... just do cv.imread() and you can cut it up like a numpy array. In fact it is a numpy array – Alexander Oct 15 '22 at 09:36
-
Does this answer your question? [Load just part of an image in python](https://stackoverflow.com/questions/19695249/load-just-part-of-an-image-in-python) – pippo1980 Oct 15 '22 at 13:19
-
https://stackoverflow.com/a/19772354/9877065 --> Load just part of an image in python – pippo1980 Oct 15 '22 at 13:22