无法在libgdx中加载渐进式jpeg图像

时间:2022-03-22 21:22:53

Here's my source

这是我的来源

package com.effect.bio;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Rectangle;

public class AppController implements ApplicationListener { 
    static final int WIDTH = 480;
    static final int HEIGHT = 320;

    private OrthographicCamera camera;
    private SpriteBatch batch;
    private Texture texture;
    private Sprite sprite;
    private Mesh mesh;
    private Rectangle glViewport;
    private float rotationSpeed;

    TiledMap map;
    TiledMapTileLayer layer;
    OrthogonalTiledMapRenderer renderer;

    @Override
    public void create() {
        float w = Gdx.graphics.getWidth();
        float h = Gdx.graphics.getHeight();

        rotationSpeed = 0.5f;

        map = new TmxMapLoader().load("data/test.tmx");
        layer = (TiledMapTileLayer) map.getLayers().get(0);

        int cols = layer.getWidth();
        int rows = layer.getHeight();

        renderer = new OrthogonalTiledMapRenderer(map, 1/32f);

        camera = new OrthographicCamera(WIDTH, HEIGHT);
        camera.position.set(WIDTH/2, HEIGHT/2, 0);

        glViewport = new Rectangle(0, 0, WIDTH, HEIGHT);
    }

    @Override
    public void dispose() {
    }

    @Override
    public void render() {      
        handleInput();
        GL10 gl = Gdx.graphics.getGL10();



        // Camera --------------------- /
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        gl.glViewport((int) glViewport.x, (int) glViewport.y,
                        (int) glViewport.width, (int) glViewport.height);

        camera.update();
        camera.apply(gl);
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    private void handleInput() {
        if(Gdx.input.isKeyPressed(Input.Keys.A)) {
                camera.zoom += 0.02;
        }
        if(Gdx.input.isKeyPressed(Input.Keys.Q)) {
                camera.zoom -= 0.02;
        }
        if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
                if (camera.position.x > 0)
                        camera.translate(-3, 0, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
                if (camera.position.x < 1024)
                        camera.translate(3, 0, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
                if (camera.position.y > 0)
                        camera.translate(0, -3, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.UP)) {
                if (camera.position.y < 1024)
                        camera.translate(0, 3, 0);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.W)) {
                camera.rotate(-rotationSpeed, 0, 0, 1);
        }
        if(Gdx.input.isKeyPressed(Input.Keys.E)) {
                camera.rotate(rotationSpeed, 0, 0, 1);
        }
}
}

I have the test.tmx file and the images inside the data folder inside assets. However, when i try to run my application I get the following error.. The vector_grass_and_sky_2_by_blackmaddog.jpg is inside the data directory but TmxMapLoader however is not able to load the files. Do I need to do anything else besides just putting the image files and the tmx files in the same place and try to load it?

我有test.tmx文件和资产内数据文件夹内的图像。但是,当我尝试运行我的应用程序时,我收到以下错误.. vector_grass_and_sky_2_by_blackmaddog.jpg位于数据目录内但TmxMapLoader却无法加载文件。除了将图像文件和tmx文件放在同一个地方并尝试加载它之外,我还需要做任何其他事情吗?

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/vector_grass_and_sky_2_by_blackmaddog.jpg
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
    at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
    at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
    at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:126)
    at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:106)
    at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:88)
    at com.effect.bio.AppController.create(AppController.java:41)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:130)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: java.io.IOException: couldn't load pixmap progressive jpeg
    at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:57)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:138)
    ... 10 more

1 个解决方案

#1


5  

This part of the exception looks relevant:

这部分异常看起来很相关:

Caused by: java.io.IOException: couldn't load pixmap progressive jpeg

Progressive JPEG images are not supported by Libgdx: https://code.google.com/p/libgdx/issues/detail?id=761

Libgdx不支持渐进式JPEG图像:https://code.google.com/p/libgdx/issues/detail?id = 761

A progressive jpeg is one that is designed for use over the internet, and is setup such that a partial download will give a useful image and it will progressively get better as more information is downloaded (vs. standard jpg where you need most of the image before you can display a whole image). Progressive support isn't really necessary for desktop or Android apps. You should be able to use most any image editing software to convert this file to a regular jpeg.

渐进式jpeg是专为在互联网上使用而设计的,并且设置为部分下载将提供有用的图像,并且随着更多信息的下载它将逐渐变得更好(与您需要大部分图像的标准jpg相比)在你可以显示整个图像之前)。桌面或Android应用程序不一定需要渐进式支持。您应该能够使用大多数图像编辑软件将此文件转换为常规jpeg。

#1


5  

This part of the exception looks relevant:

这部分异常看起来很相关:

Caused by: java.io.IOException: couldn't load pixmap progressive jpeg

Progressive JPEG images are not supported by Libgdx: https://code.google.com/p/libgdx/issues/detail?id=761

Libgdx不支持渐进式JPEG图像:https://code.google.com/p/libgdx/issues/detail?id = 761

A progressive jpeg is one that is designed for use over the internet, and is setup such that a partial download will give a useful image and it will progressively get better as more information is downloaded (vs. standard jpg where you need most of the image before you can display a whole image). Progressive support isn't really necessary for desktop or Android apps. You should be able to use most any image editing software to convert this file to a regular jpeg.

渐进式jpeg是专为在互联网上使用而设计的,并且设置为部分下载将提供有用的图像,并且随着更多信息的下载它将逐渐变得更好(与您需要大部分图像的标准jpg相比)在你可以显示整个图像之前)。桌面或Android应用程序不一定需要渐进式支持。您应该能够使用大多数图像编辑软件将此文件转换为常规jpeg。