private static BufferedImage scaleDown(BufferedImage sourceImage, int targetWidth, int targetHeight) { int sourceWidth = sourceImage.getWidth(); int sourceHeight = sourceImage.getHeight(); BufferedImage targetImage = new BufferedImage(targetWidth, targetHeight, sourceImage.getType()); Graphics2D g = targetImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(sourceImage, 0, 0, targetWidth, targetHeight, 0, 0, sourceWidth, sourceHeight, null); g.dispose(); return targetImage; }
private BufferedImage resize(BufferedImage input, int targetWidth, int targetHeight) { BufferedImage result = new BufferedImage(targetWidth, targetHeight, input.getType()); Graphics2D g = result.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(input, 0, 0, targetWidth, targetHeight, null); g.dispose(); return result; } }
@Override public PImage __clone(Environment env, TraceInfo trace) { BufferedImage copyOfImage = new BufferedImage(getWidth(), getHeight(), image.getType()); Graphics g = copyOfImage.createGraphics(); g.drawImage(image, 0, 0, null); return new PImage(env, copyOfImage); } }
protected ResizableImage resizeImage(int width, int targetHeight, BufferedImage image) throws IOException { try { int imageType = (image.getType() > 0) ? image.getType() : BufferedImage.TYPE_4BYTE_ABGR; BufferedImage resizedImage = new BufferedImage(width, targetHeight, imageType); fillWithWhiteBackground(resizedImage); resizedImage.setData(image.getRaster()); return new ResizedImage(resizedImage, screenshotFile); } catch (Throwable e) { throw new IllegalArgumentException(e); } }
/** * A convenience method for getting ARGB pixels from an image. This tries to avoid the performance * penalty of BufferedImage.getRGB unmanaging the image. * @param image a BufferedImage object * @param x the left edge of the pixel block * @param y the right edge of the pixel block * @param width the width of the pixel array * @param height the height of the pixel array * @param pixels the array to hold the returned pixels. May be null. * @return the pixels * @see #setRGB */ public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { int type = image.getType(); if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) return (int[]) image.getRaster().getDataElements(x, y, width, height, pixels); return image.getRGB(x, y, width, height, pixels, 0, width); }
pParam.getDestinationType() != null && pParam.getDestinationType().getBufferedImageType() != image.getType())) { BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), getWidth(pIndex), getHeight(pIndex)); Graphics2D g = destination.createGraphics(); try { g.setComposite(AlphaComposite.Src); g.drawImage(image, 0, 0, null);
private void getImagePixels() { int w = image.getWidth(); int h = image.getHeight(); int type = image.getType(); if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) { BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = temp.createGraphics(); g.drawImage(image, 0, 0, null); image = temp; } pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); }
@Signature public PImage resize(int width, int height) { BufferedImage image = new BufferedImage(width, height, this.image.getType()); Graphics2D gc = image.createGraphics(); gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gc.drawImage(this.image, 0, 0, width, height, null); gc.dispose(); this.image = image; return this; }
public static BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException { int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double scaleX = (double)width/imageWidth; double scaleY = (double)height/imageHeight; AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return bilinearScaleOp.filter( image, new BufferedImage(width, height, image.getType())); }
protected ResizableImage resizeImage(int width, int targetHeight, BufferedImage image) throws IOException { try { int imageType = (image.getType() > 0) ? image.getType() : BufferedImage.TYPE_4BYTE_ABGR; BufferedImage resizedImage = new BufferedImage(width, targetHeight, imageType); fillWithWhiteBackground(resizedImage); resizedImage.setData(image.getRaster()); return new ResizedImage(resizedImage, screenshotFile); } catch (Throwable e) { throw new IllegalArgumentException(e); } }
/** * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance * penalty of BufferedImage.setRGB unmanaging the image. * @param image a BufferedImage object * @param x the left edge of the pixel block * @param y the right edge of the pixel block * @param width the width of the pixel array * @param height the height of the pixel array * @param pixels the array of pixels to set * @see #getRGB */ public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { int type = image.getType(); if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) image.getRaster().setDataElements(x, y, width, height, pixels); else image.setRGB(x, y, width, height, pixels, 0, width); }
splitImage = new BufferedImage(region.width, region.height, page.getType()); BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2, page.getType()); Graphics2D g2 = paddedImage.createGraphics(); g2.drawImage(splitImage, padding, padding, null); g2.dispose(); return paddedImage;
/** * Simple resize, does not maintain aspect ratio * @param image * @param width * @param height * @return */ public static BufferedImage resize(BufferedImage image, int width, int height) { int type = image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : image .getType(); BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(image, 0, 0, width, height, null); g.dispose(); return resizedImage; }
/** * A convenience method for getting ARGB pixels from an image. This tries to avoid the * performance penalty of BufferedImage.getRGB unmanaging the image. * * @param image a BufferedImage object * @param x the left edge of the pixel block * @param y the right edge of the pixel block * @param width the width of the pixel array * @param height the height of the pixel array * @param pixels the array to hold the returned pixels. May be null. * @return the pixels * @see #setRGB */ public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { int type = image.getType(); if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) { return (int[]) image.getRaster().getDataElements(x, y, width, height, pixels); } return image.getRGB(x, y, width, height, pixels, 0, width); }
splitImage = new BufferedImage(region.width, region.height, page.getType()); BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2, page.getType()); Graphics2D g2 = paddedImage.createGraphics(); g2.drawImage(splitImage, padding, padding, null); g2.dispose(); return paddedImage;
splitImage = extractImage(img, region, outputDirFile, 0); if (region.width != region.originalWidth || region.height != region.originalHeight) { BufferedImage originalImg = new BufferedImage(region.originalWidth, region.originalHeight, img.getType()); Graphics2D g2 = originalImg.createGraphics(); g2.drawImage(splitImage, (int) region.offsetX, (int) (region.originalHeight - region.height - region.offsetY), null); g2.dispose(); splitImage = originalImg;
/** * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance * penalty of BufferedImage.setRGB unmanaging the image. * * @param image a BufferedImage object * @param x the left edge of the pixel block * @param y the right edge of the pixel block * @param width the width of the pixel array * @param height the height of the pixel array * @param pixels the array of pixels to set * @see #getRGB */ public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { int type = image.getType(); if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) { image.getRaster().setDataElements(x, y, width, height, pixels); } else { image.setRGB(x, y, width, height, pixels, 0, width); } } }
/** * Extracts image pixels into byte array "pixels" */ protected void getImagePixels() { int w = image.getWidth(); int h = image.getHeight(); int type = image.getType(); if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) { // create new image with right size/format BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = temp.createGraphics(); g.drawImage(image, 0, 0, null); image = temp; } pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); }
splitImage = extractImage(img, region, outputDirFile, 0); if (region.width != region.originalWidth || region.height != region.originalHeight) { BufferedImage originalImg = new BufferedImage(region.originalWidth, region.originalHeight, img.getType()); Graphics2D g2 = originalImg.createGraphics(); g2.drawImage(splitImage, (int) region.offsetX, (int) (region.originalHeight - region.height - region.offsetY), null); g2.dispose(); splitImage = originalImg;