水平镜像

来自:http://bbs.eyuyan.com/read.php?tid=67694
1. public static Image verticalMirror(Image img) {
2.
3. int[] rgbOutput = null;
4. int[] rgbInput = null;
5. int width = 0, height = 0;
6. int[][] tempArr = null;
7. try {
8. width = img.getWidth();
9. height = img.getHeight();
10. rgbInput = new int[width * height];
11. rgbOutput = new int[width * height];
12. img.getRGB(rgbInput, 0, width, 0, 0, width, height);
13. int i, j, k;
14. k = 0;
15. tempArr = new int[height][width];
16.
17. for (i = 0; i < height; i++) {
18. for (j = 0; j < width; j++) {
19. tempArr[i][j] = rgbInput[k++];
20. }
21. }
22. rgbInput = null; // 显式地设置为空值,告诉系统可以垃圾回收
23. int[][] tempArr1 = new int[height][width];
24. for (i = 0; i < height; i++) {
25. for (j = 0; j < width; j++) {
26. tempArr1[i][width - 1 - j] = tempArr[i][j];
27. }
28. }
29. tempArr = null; // 显式地设置为空值,告诉系统可以垃圾回收
30. k = 0;
31. for (i = 0; i < height; i++) {
32. for (j = 0; j < width; j++) {
33. rgbOutput[k] = tempArr1[i][j];
34. k++;
35.
36. }
37. }
38. tempArr1 = null; // 显式地设置为空值,告诉系统可以垃圾回收
39. // return img;
40. return Image.createRGBImage(rgbOutput, width, height, true);
41. } catch (OutOfMemoryError e) {
42. // e.printStackTrace();
43. ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
44. return img;
45. } finally {
46. rgbOutput = null;
47. }
48.
49. }
50.
51. /*************************************************************************** * * 水平镜像的方法 */
52. public static Image horizontalMirror(Image img) {
53.
54. int[] rgbOutput = null;
55. int[] rgbInput = null;
56. int width = 0, height = 0;
57. int[][] tempArr = null;
58. int[][] tempArr1 = null;
59. try {
60. width = img.getWidth();
61. height = img.getHeight();
62. rgbInput = new int[width * height];
63. rgbOutput = new int[width * height];
64. img.getRGB(rgbInput, 0, width, 0, 0, width, height);
65. int i, j, k;
66. k = 0;
67. tempArr = new int[height][width];
68.
69. for (i = 0; i < height; i++) {
70. for (j = 0; j < width; j++) {
71. tempArr[i][j] = rgbInput[k++];
72. }
73. }
74. rgbInput = null; // 显式地设置为空值,告诉系统可以垃圾回收
75. tempArr1 = new int[height][width];
76. for (i = 0; i < height; i++) {
77. for (j = 0; j < width; j++) {
78. tempArr1[height - 1 - i][j] = tempArr[i][j];
79. }
80. }
81. tempArr = null; // 显式地设置为空值,告诉系统可以垃圾回收
82. k = 0;
83. for (i = 0; i < height; i++) {
84. for (j = 0; j < width; j++) {
85. rgbOutput[k] = tempArr1[i][j];
86. k++;
87.
88. }
89. }
90. tempArr1 = null; // 显式地设置为空值,告诉系统可以垃圾回收
91. return Image.createRGBImage(rgbOutput, width, height, true);
92. } catch (OutOfMemoryError e) {
93. // e.printStackTrace();
94. ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
95. return img;
96. } finally {
97. rgbOutput = null;
98. }
99.
100. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值