Couldn't read Pixmap from PNG file / incorrect header check?

This has been frustrating me for the past hour… :cranky: I’m simply trying to read a PNG file into a Pixmap object:

	void buildLevel(String mapFile){
		Pixmap pm = PixmapIO.readCIM(Gdx.files.internal("data/"+mapFile));
   // other stuff

But I get the following error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't read Pixmap from file 'data/level1.png'
	at com.badlogic.gdx.graphics.PixmapIO$CIM.read(PixmapIO.java:136)
	at com.badlogic.gdx.graphics.PixmapIO.readCIM(PixmapIO.java:48)
	at com.me.itlogap.LogapLevel.buildLevel(LogapLevel.java:125)
	at com.me.itlogap.LogapLevel.<init>(LogapLevel.java:49)
	at com.me.itlogap.ItLoGaP.render(ItLoGaP.java:356)
	at com.badlogic.gdx.Game.render(Game.java:46)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:202)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: java.util.zip.ZipException: incorrect header check
	at java.util.zip.InflaterInputStream.read(Unknown Source)
	at java.util.zip.InflaterInputStream.read(Unknown Source)
	at java.io.DataInputStream.readInt(Unknown Source)
	at com.badlogic.gdx.graphics.PixmapIO$CIM.read(PixmapIO.java:115)
	... 7 more

I created the png file with GraphicsGale. I even ran pngcrush on it with the -new option to try and clean any formatting stuff that might be messing up the file i/o… but to no avail. Any idea how to solve this?

This can help as a hint:

Actually, instead of using PixmapIO, I just did:

Pixmap pm = new Pixmap(Gdx.files.internal("data/"+mapFile));

But even then, I’m curious why the initial approach resulted in that error.

CIM is a custom format for LibGDX. It’s quicker and uses less working memory to read/write images; but is only really useful if the images don’t need to be viewed outside of your LibGDX game.

The readCIM method only reads “.cim” files (created by PixmapIO.writeCIM). If you want to read PNG, you need to use the Pixmap constructor like in your latest post.

You can learn more about textures and pixmaps here: