如何将像素图旋转90º以在libgdx中绘制纹理? [英] How to rotate a pixmap by 90º to draw to a texture in libgdx?

查看:102
本文介绍了如何将像素图旋转90º以在libgdx中绘制纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将Pixmap旋转90度.我看到了一个答案,该答案达到了f 唇形的Pixmap .我需要旋转纵向方向的图像以在Pixmap级别上将其横向放置,以稍后使用它们创建纹理.

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.

推荐答案

类似于翻转像素图方法,我实现了像这样旋转90º的Pixmap:

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;
}

请注意,宽度&旋转90º后,高度会被交换

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

这篇关于如何将像素图旋转90º以在libgdx中绘制纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆