我有一种通过像素翻转图像的方法。但这样做会创造一个全新的形象。我怎么能修改现有图像?
private GImage flipHorizontal(GImage img) {
int[][] array = img.getPixelArray();
//width in pixels of each row of image
int width = array[0].length;
//loops through each row of the image
for (int i = 0; i < array.length; i++) {
//in each row flip each pixel horizontally
for (int p1 = 0; p1 < width / 2; p1++) {
int p2 = width - p1 - 1;
int temp = array[i][p1];
array[i][p1] = array[i][p2];
array[i][p2] = temp;
}
}
return ( new GImage(array));
}