| 颜色反转 |
|
|
|
|
Author: jacky | Date: 2008-04-01 | View: 895
|
会员博客 -
个人博客
| ||||
|
主要是操作下面的工具类
public static final int SHIFT_BLUE_TO_RED = 4; public static final int SHIFT_BLUE_TO_GREEN = 5; public static int[] flipImageColor(Image source, int shiftType) { // we start by getting the image data into an int array - the number // of 32-bit ints is equal to the width multiplied by the height int[] rgbData = new int[(source.getWidth() * source.getHeight())]; source.getRGB(rgbData, 0, source.getWidth(), 0, 0, source.getWidth(), source.getHeight()); // now go through every pixel and adjust it's color for (int i = 0; i < rgbData.length; i++) { int p = rgbData[i]; // split out the different byte components of the pixel by // applying // a mask so we only get what we need, then shift it to make it // a normal number we can play around with int a = ((p & 0xff000000) >> 24); int r = ((p & 0x00ff0000) >> 16); int g = ((p & 0x0000ff00) >> 8); int b = ((p & 0x000000ff) >> 0); int ba = a, br = r, bb = b, bg = g; // backup copies // flip the colors around according to the operation required switch (shiftType) { case SHIFT_RED_TO_GREEN: g = r; r = bg; break; case SHIFT_RED_TO_BLUE: b = r; r = bb; break; case SHIFT_GREEN_TO_BLUE: g = b; b = bg; break; case SHIFT_GREEN_TO_RED: g = r; r = bg; break; case SHIFT_BLUE_TO_RED: b = r; r = bb; break; case SHIFT_BLUE_TO_GREEN: b = g; g = bb; break; } // shift all our values back in rgbData[i] = (a << 24) | (r << 16) | (g << 8) | b; } return rgbData; } } 调用: int[] targetImage= GraphicsUtil.flipImageColor(srcImage, GraphicsUtil.SHIFT_RED_TO_BLUE); g.drawRGB(targetImage,0,srcImage.getWidth(), 30, srcImage.getHeight() + 40, srcImage.getWidth(),srcImage.getHeight(), true);
本文关键字: 颜色 反转 阅读数: 896 | 打印 | E-mail
|
||||||||
| 最近更新 ( 2008-04-03 ) | ||||||||
| (J2me代码优化) < 上一篇 | 下一篇 > (Eclipse下J2ME开发环境的配置) |
|---|