http://lzy32.blog.163.com/blog/static/3768032320076209273297/
public static Image createImage(Image image,
int x,
int y,
int width,
int height,
int transform)
其中:transform就可以指定要做的操作,比如水平镜像,转90度等
/***************************************************************************
*
* 垂直镜像的方法
*/
public static Image verticalMirror(Image img) {
int[] rgbOutput = null;
int[] rgbInput = null;
int width = 0, height = 0;
int[][] tempArr = null;
try {
width = img.getWidth();
height = img.getHeight();
rgbInput = new int[width * height];
rgbOutput = new int[width * height];
img.getRGB(rgbInput, 0, width, 0, 0, width, height);
int i, j, k;
k = 0;
tempArr = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
tempArr[i][j] = rgbInput[k++];
rgbInput = null;// 显式地设置为空值,告诉系统可以垃圾回收
int[][] tempArr1 = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
tempArr1[i][width - 1 - j] = tempArr[i][j];
}
tempArr = null;// 显式地设置为空值,告诉系统可以垃圾回收
k = 0;
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
rgbOutput[k] = tempArr1[i][j];
k++;
}
tempArr1 = null;// 显式地设置为空值,告诉系统可以垃圾回收
// return img;
return Image.createRGBImage(rgbOutput, width, height, true);
} catch (OutOfMemoryError e) {
// e.printStackTrace();
ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
return img;
} finally {
rgbOutput = null;
}
}
/***************************************************************************
*
* 水平镜像的方法
*/
public static Image horizontalMirror(Image img) {
int[] rgbOutput = null;
int[] rgbInput = null;
int width = 0, height = 0;
int[][] tempArr = null;
int[][] tempArr1 = null;
try {
width = img.getWidth();
height = img.getHeight();
rgbInput = new int[width * height];
rgbOutput = new int[width * height];
img.getRGB(rgbInput, 0, width, 0, 0, width, height);
int i, j, k;
k = 0;
tempArr = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
tempArr[i][j] = rgbInput[k++];
rgbInput = null;// 显式地设置为空值,告诉系统可以垃圾回收
tempArr1 = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
tempArr1[height - 1 - i][j] = tempArr[i][j];
}
tempArr = null;// 显式地设置为空值,告诉系统可以垃圾回收
k = 0;
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
rgbOutput[k] = tempArr1[i][j];
k++;
}
tempArr1 = null;// 显式地设置为空值,告诉系统可以垃圾回收
return Image.createRGBImage(rgbOutput, width, height, true);
} catch (OutOfMemoryError e) {
// e.printStackTrace();
ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
return img;
} finally {
rgbOutput = null;
}
}
public static Image createImage(Image image,
int x,
int y,
int width,
int height,
int transform)
其中:transform就可以指定要做的操作,比如水平镜像,转90度等
/***************************************************************************
*
* 垂直镜像的方法
*/
public static Image verticalMirror(Image img) {
int[] rgbOutput = null;
int[] rgbInput = null;
int width = 0, height = 0;
int[][] tempArr = null;
try {
width = img.getWidth();
height = img.getHeight();
rgbInput = new int[width * height];
rgbOutput = new int[width * height];
img.getRGB(rgbInput, 0, width, 0, 0, width, height);
int i, j, k;
k = 0;
tempArr = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
tempArr[i][j] = rgbInput[k++];
rgbInput = null;// 显式地设置为空值,告诉系统可以垃圾回收
int[][] tempArr1 = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
tempArr1[i][width - 1 - j] = tempArr[i][j];
}
tempArr = null;// 显式地设置为空值,告诉系统可以垃圾回收
k = 0;
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
rgbOutput[k] = tempArr1[i][j];
k++;
}
tempArr1 = null;// 显式地设置为空值,告诉系统可以垃圾回收
// return img;
return Image.createRGBImage(rgbOutput, width, height, true);
} catch (OutOfMemoryError e) {
// e.printStackTrace();
ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
return img;
} finally {
rgbOutput = null;
}
}
/***************************************************************************
*
* 水平镜像的方法
*/
public static Image horizontalMirror(Image img) {
int[] rgbOutput = null;
int[] rgbInput = null;
int width = 0, height = 0;
int[][] tempArr = null;
int[][] tempArr1 = null;
try {
width = img.getWidth();
height = img.getHeight();
rgbInput = new int[width * height];
rgbOutput = new int[width * height];
img.getRGB(rgbInput, 0, width, 0, 0, width, height);
int i, j, k;
k = 0;
tempArr = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
tempArr[i][j] = rgbInput[k++];
rgbInput = null;// 显式地设置为空值,告诉系统可以垃圾回收
tempArr1 = new int[height][width];
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
tempArr1[height - 1 - i][j] = tempArr[i][j];
}
tempArr = null;// 显式地设置为空值,告诉系统可以垃圾回收
k = 0;
for (i = 0; i < height; i++)
for (j = 0; j < width; j++) {
rgbOutput[k] = tempArr1[i][j];
k++;
}
tempArr1 = null;// 显式地设置为空值,告诉系统可以垃圾回收
return Image.createRGBImage(rgbOutput, width, height, true);
} catch (OutOfMemoryError e) {
// e.printStackTrace();
ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
return img;
} finally {
rgbOutput = null;
}
}