六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 60|回复: 0

水平镜像

[复制链接]

升级  21.33%

20

主题

20

主题

20

主题

秀才

Rank: 2

积分
82
 楼主| 发表于 2013-2-7 00:54:04 | 显示全部楼层 |阅读模式
来自: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. }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表