How to rotate a pixmap by 90º to draw to a texture in libgdx?

╄→гoц情女王★ 提交于 2019-12-12 20:17:29

问题


I need to rotate a Pixmap by 90 degrees. I have seen an answer that achieves a flipped Pixmap. I need to rotate images that are in portrait orientation to landscape already on the Pixmap-level to later create textures out of them.


回答1:


similar to the flip pixmap method I achieved a 90º rotated Pixmap like this:

private Pixmap rotatePixmap (Pixmap srcPix){
    final int width = srcPix.getWidth();
    final int height = srcPix.getHeight();
    Pixmap rotatedPix = new Pixmap(height, width, srcPix.getFormat());

    for (int x = 0; x < height; x++) {
        for (int y = 0; y < width; y++) {
            rotatedPix.drawPixel(x, y, srcPix.getPixel(y, x));
        }
    }

    srcPix.dispose();
    return rotatedPix;
}

Note that also width & height get swapped after the 90º rotation



来源:https://stackoverflow.com/questions/34362684/how-to-rotate-a-pixmap-by-90%c2%ba-to-draw-to-a-texture-in-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!