【问题标题】:How to rotate a pixmap by 90º to draw to a texture in libgdx?如何将像素图旋转 90º 以绘制到 libgdx 中的纹理?
【发布时间】:2016-03-25 13:54:56
【问题描述】:

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

【问题讨论】:

    标签: java libgdx textures pixmap


    【解决方案1】:

    类似于flip pixmap method,我实现了这样的 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º 旋转后宽度和高度也会交换

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 2014-09-05
      • 2017-10-09
      • 2017-11-29
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多