List of utility methods to do BufferedImage Subimage
BufferedImage | getSubImage(BufferedImage image, int x, int y, int w, int h) get Sub Image return image.getSubimage(x, y, w, h);
|
BufferedImage | getSubimage(BufferedImage image, int x, int y, int w, int h) get Subimage BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = newImage.createGraphics(); g.drawRenderedImage(image, AffineTransform.getTranslateInstance(-x, -y)); g.dispose(); return newImage; |
BufferedImage | getSubImage(BufferedImage image, int x, int y, int width, int height) A replacement for the standard BufferedImage.getSubimage method.
int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage tmp = new BufferedImage(width, height, type); Graphics2D g2 = tmp.createGraphics(); g2.drawImage(image.getSubimage(x, y, width, height), 0, 0, null); g2.dispose(); return tmp; |
BufferedImage | getSubimage(BufferedImage image, int x, int y, int width, int height) get Subimage if (width > image.getWidth() - x) width = image.getWidth() - x; if (height > image.getHeight() - y) height = image.getHeight() - y; return image.getSubimage(x, y, width, height); |
BufferedImage | getSubimage(BufferedImage image, int x, int y, int width, int height) get Subimage if ((x < 0) || (width < 0) || (x + width > image.getWidth()) || (y < 0) || (height < 0) || (y + height > image.getHeight())) throw new IllegalArgumentException(); BufferedImage subimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int[] rgbBuffer = new int[width * height]; image.getRGB(x, y, width, height, rgbBuffer, 0, width); subimage.setRGB(0, 0, width, height, rgbBuffer, 0, width); return subimage; ... |
BufferedImage | getSubImage(BufferedImage img, int x, int y, int w, int h) For some reason, BufferedImage.getSubimage returns something which is incompatible with JAI. BufferedImage result = new BufferedImage(w, h, img.getType()); Graphics g = result.getGraphics(); g.drawImage(img, 0, 0, w, h, x, y, w, h, null); g.dispose(); return result; |
BufferedImage | getSubImage(BufferedImage img, Rectangle area) get Sub Image BufferedImage newImg = new BufferedImage(area.width, area.height, BufferedImage.TYPE_INT_ARGB); int i = 0; int j = 0; int x2 = area.x + area.width; int y2 = area.y + area.height; for (int x = area.x; x < x2; ++x) { for (int y = area.y; y < y2; ++y) { newImg.setRGB(i, j++, img.getRGB(x, y)); ... |
BufferedImage | getSubImage(BufferedImage srcImage, int x, int y, int factorWidth, int factorHeight) Gets the sub image from original image by specified X,Y coords and Width and Height. if (factorWidth < srcImage.getWidth() && factorHeight < srcImage.getHeight()) { return srcImage.getSubimage(x, y, factorWidth, factorHeight); return srcImage; |