2

我需要将像素图旋转 90 度。我已经看到了实现 af lipped Pixmap的答案。我需要在 Pixmap 级别上将纵向的图像旋转为横向,以便稍后从中创建纹理。

4

1 回答 1

4

类似于翻转像素图方法,我实现了 90º 旋转像素图,如下所示:

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º 旋转后宽度和高度也会交换

于 2015-12-18T19:33:08.167 回答