如何翻转像素图以绘制到libgdx中的纹理?

所以我要做的是通过将pixmaps绘制到纹理来为我的游戏生成背景图像。 到目前为止,我可以做到这一点,但现在我需要绘制在X或Y轴上翻转到纹理的像素图。 但是我找不到任何可以做到的事情。 pixmap类不提供该function。 然后我想我可以在纹理上绘制一个翻转的纹理区域,但到目前为止我还没有找到如何做到这一点。 所以我想知道我怎么能做这样的事情,是否可以用其他java库翻转png图像,然后从翻转的图像创建一个像素图?

除了迭代像素之外,我也没有看到其他选项:

public Pixmap flipPixmap(Pixmap src) { final int width = src.getWidth(); final int height = src.getHeight(); Pixmap flipped = new Pixmap(width, height, src.getFormat()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { flipped.drawPixel(x, y, src.getPixel(width - x - 1, y)); } } return flipped; } 

这是一个不需要创建新Pixmap的解决方案。 还可以修改此代码以通过交换像素图图像的角而不是交换图像的相对侧上的像素来水平和垂直地翻转Pixmap。

 public static void flipPixmap( Pixmap p ){ int w = p.getWidth(); int h = p.getHeight(); int hold; //change blending to 'none' so that alpha areas will not show //previous orientation of image p.setBlending(Pixmap.Blending.None); for (int y = 0; y < h / 2; y++) { for (int x = 0; x < w / 2; x++) { //get color of current pixel hold = p.getPixel(x,y); //draw color of pixel from opposite side of pixmap to current position p.drawPixel(x,y, p.getPixel(wx-1, y)); //draw saved color to other side of pixmap p.drawPixel(wx-1,y, hold); //repeat for height/width inverted pixels hold = p.getPixel(x, hy-1); p.drawPixel(x,hy-1, p.getPixel(wx-1,hy-1)); p.drawPixel(wx-1,hy-1, hold); } } //set blending back to default p.setBlending(Pixmap.Blending.SourceOver); }