Java examples for 2D Graphics:BufferedImage Pixel
apply pixel modifier to the Java Micro edition image.
/*// w ww . ja v a 2s. co m * This file is a part of the TUBE42 imagelib, released under the LGPL license. * * Development page: https://github.com/tube42/imagelib * License: http://www.gnu.org/copyleft/lesser.html */ import javax.microedition.lcdui.*; public class Main{ /** * apply pixel modifier to the image. * This function also demonstrates use of in-place image modification * which consumes less memory. * */ public static Image applyModifier(Image image, PixelModifier modifier) { return applyModifier(image, modifier, false); } public static Image applyModifier(Image image, PixelModifier modifier, boolean modify_original) { // 1. allocate needed buffers final int w = image.getWidth(); final int h = image.getHeight(); int[] buffer1 = new int[w]; int[] buffer2 = new int[w]; // 2. get image for in-place modification or create new Image ret = modify_original ? image : Image.createImage(w, h); Graphics g = ret.getGraphics(); // 3. for each row, get the pixels for (int y = 0; y < h; y++) { image.getRGB(buffer1, 0, w, 0, y, w, 1); modifier.apply(buffer1, buffer2, w, y); g.drawRGB(buffer2, 0, w, 0, y, w, 1, true); } return ret; } }