在MIDP2.0中操作图片像素[6]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:


GraphicsUtil.java


  1. import javax.microedition.lcdui.Image;
  2. /**
  3.  * 
  4.  * @author Jagie
  5.  * 
  6.  */
  7. public class GraphicsUtil {
  8.     public static final int SHIFT_RED_TO_GREEN = 0;
  9.     public static final int SHIFT_RED_TO_BLUE = 1;
  10.     public static final int SHIFT_GREEN_TO_BLUE = 2;
  11.     public static final int SHIFT_GREEN_TO_RED = 3;
  12.     public static final int SHIFT_BLUE_TO_RED = 4;
  13.     public static final int SHIFT_BLUE_TO_GREEN = 5;
  14.     public static int[] flipImageColor(Image source, int shiftType) {
  15.         // we start by getting the image data into an int array - the number
  16.         // of 32-bit ints is equal to the width multiplied by the height
  17.         int[] rgbData = new int[(source.getWidth() * source.getHeight())];
  18.         source.getRGB(rgbData, 0, source.getWidth(), 0, 0, source.getWidth(),
  19.                 source.getHeight());
  20.         // now go through every pixel and adjust it's color
  21.         for (int i = 0; i < rgbData.length; i++) {
  22.             int p = rgbData[i];
  23.             // split out the different byte components of the pixel by
  24.             // applying
  25.             // a mask so we only get what we need, then shift it to make it
  26.             // a normal number we can play around with
  27.         

本文关键:在MIDP2.0中操作图片像素
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top