/** * Draw an image squeezed along the horizontal and/or vertical dimensions (no preservation of * aspect ratio) centered at (x, y). * * @param g - object to draw onto * @param x - horizontal center of where to draw the resulting image * @param y - vertical center of where to draw the resulting image * @param inputImageARGB * @param outputImageARGB - often this is the same as inputImageARGB for speed * @param srcW - source image width * @param srcH - source image height * @param maxW - target width * @param maxH - target height * @param processAlpha - set false for speed if the image is opaque */ public static void drawFlipshade( final Graphics g, final int x, final int y, final int[] inputImageARGB, final int[] outputImageARGB, int srcW, int srcH, int maxW, int maxH, final boolean processAlpha) { if (maxW < 1 || maxH < 1 || srcW < 1 || srcH < 1) { throw new IllegalArgumentException( "drawFlipshade requires maxW, maxH, srcW and srcH be >= 1"); } if (inputImageARGB == null || outputImageARGB == null) { throw new NullPointerException( "drawFlipshade requires non-null input and output image buffers"); } while (srcW >> 1 > maxW && srcH >> 1 > maxH) { JMEImageUtils.half(inputImageARGB, inputImageARGB, srcW, srcH >>= 1); srcW >>= 1; } if (srcW >> 1 == maxW && srcH >> 1 == maxH) { JMEImageUtils.half(inputImageARGB, outputImageARGB, maxW, maxH); } else { maxW = Math.min(srcW, maxW); maxH = Math.min(srcH, maxH); JMEImageUtils.fivePointSampleDownscale( inputImageARGB, outputImageARGB, srcW, srcH, maxW, maxH); } g.drawRGB(outputImageARGB, 0, maxW, x - (maxW >> 1), y - (maxH >> 1), maxW, maxH, processAlpha); }
/* (non-Javadoc) * @see javax.microedition.lcdui.Canvas#paint(javax.microedition.lcdui.Graphics) */ public void paintAnimation(Graphics g) { g.drawRGB( this.currentScreenRgb, 0, this.screenWidth, 0, 0, this.screenWidth, this.screenHeight, false); }
/* * 图片叠加,将src和image合成一张图片,x_pos,y_pos一般为0,0,也可以为自定义值 */ public Image effect_image_add_image(Image src, Image image, int x_pos, int y_pos) { Image temp = Image.createImage(src.getWidth(), src.getHeight()); Graphics g = temp.getGraphics(); // g.drawImage(src,x_pos,y_pos,Graphics.LEFT|Graphics.TOP); // g.drawImage(image,x_pos,y_pos,Graphics.LEFT|Graphics.TOP);*/ int alpha = 168; int[] srcRgbdata = new int[src.getWidth() * src.getHeight()]; int[] desRgbdata = new int[image.getWidth() * image.getHeight()]; src.getRGB(srcRgbdata, 0, src.getWidth(), 0, 0, src.getWidth(), src.getHeight()); image.getRGB(desRgbdata, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight()); g.drawRGB( getTransImg(alpha, srcRgbdata, desRgbdata), 0, src.getWidth(), 0, 0, src.getWidth(), src.getHeight(), false); src = null; image = null; return temp; }