Refine search
private BufferedImage smaller(BufferedImage im) { if (im == null) { return null; } final int nb = 1; return im.getSubimage(nb, nb, im.getWidth() - 2 * nb, im.getHeight() - 2 * nb); }
@Override final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormatOption, long seed) throws IOException { final BufferedImage im = createImage(); final ImageData imageData = new ImageDataSimple(im.getWidth(), (int) maxYpos); PngIO.write(im.getSubimage(0, 0, imageData.getWidth(), imageData.getHeight()), os, 96); return imageData; }
final BufferedImage source = ImageIO.read(new File("<sourceDir>/1fby-6t-555d.png")); int idx = 0; for (int y = 0; y < source.getHeight(); y += 32) { ImageIO.write(source.getSubimage(0, y, 32, 32), "png", new File("<sourceDir>/1fby-6t-555d_" + idx++ + ".png")); }
@Override public void addAugmentedImages(List<BufferedImage> images) { int l = images.size(); for (int i = 0; i < l; i++) { BufferedImage im = images.get(i); images.add(im.getSubimage(0, 0, cropX, cropY)); images.add(im.getSubimage(im.getWidth() - cropX, 0, cropX, cropY)); images.add(im.getSubimage(0, im.getHeight() - cropY, cropX, cropY)); images.add(im.getSubimage(im.getWidth() - cropX, im.getHeight() - cropY, cropX, cropY)); images.add(im.getSubimage((im.getWidth() - cropX) / 2, (im.getHeight() - cropY) / 2, cropX, cropY)); } images.subList(0, l).clear(); }
@Override public OcrResult findOcrText(BufferedImage image, Rect rect) throws ValidationErrorException { if (rect.getRight() > image.getWidth() && rect.getBottom() > rect.getHeight()) { throw new ValidationErrorException("Could not extract element image. Looks like it is located outside of screenshot area"); } try { BufferedImage croppedImage = image.getSubimage(rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight()); GoogleModel model = getGoogleModel(croppedImage); if (model.responses != null && !model.responses.isEmpty()) { String resultedText = model.responses.get(0).fullTextAnnotation.text; if (resultedText == null) { resultedText = ""; } return new OcrResult(new String(resultedText.getBytes(Charset.forName("utf-8"))), rect); } else { throw new NullPointerException("Got empty result"); } } catch (Exception e) { throw new ValidationErrorException("Google vision API error: " + e.getMessage(), e); } }
private static ArrayList<BufferedImage> clipBDIndexImage(BufferedImage image) { ArrayList<BufferedImage> images = new ArrayList<BufferedImage>(); int[] indices = getWidthForNumber(image, 0); while (indices != null) { int numberWidth = indices[1] - indices[0] + 1; if (numberWidth > 10) {//宽度太小的是逗号,不需要保存该数据 BufferedImage subImage = image.getSubimage(indices[0], 0, numberWidth, image.getHeight()); images.add(subImage); } indices = getWidthForNumber(image, indices[1]+1); } return images; }
BufferedImage srcImage = page.getSubimage(region.left, region.top, region.height, region.width); splitImage = new BufferedImage(region.width, region.height, page.getType()); op.filter(srcImage, splitImage); } else { splitImage = page.getSubimage(region.left, region.top, region.width, region.height); BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2, page.getType()); Graphics2D g2 = paddedImage.createGraphics();
private static ImageIcon createIcon(BufferedImage source) { source = source.getSubimage(0, 0, source.getWidth(), source.getWidth()); Image scaledImage = source.getScaledInstance(64, 64, java.awt.Image.SCALE_FAST); return new ImageIcon(scaledImage); }
private BufferedImage cutLeftRight(BufferedImage origin, PlateHorizontalGraph graph) { graph.applyProbabilityDistributor(new Graph.ProbabilityDistributor(0f, 0f, 2, 2)); List<Peak> peaks = graph.findPeak(); if (peaks.size() != 0) { Peak p = peaks.get(0); return origin.getSubimage(p.getLeft(), 0, p.getDiff(), getImage().getHeight()); } return origin; }
BufferedImage srcImage = page.getSubimage(region.left, region.top, region.height, region.width); splitImage = new BufferedImage(region.width, region.height, page.getType()); op.filter(srcImage, splitImage); } else { splitImage = page.getSubimage(region.left, region.top, region.width, region.height); BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2, page.getType()); Graphics2D g2 = paddedImage.createGraphics();
public static void takeScreenshot(String screenshotPathAndName, WebDriver driver) { File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { int height = driver.manage().window().getSize().getHeight(); BufferedImage img = ImageIO.read(scrFile); BufferedImage dest = img.getSubimage(0, 0, img.getWidth(), height); ImageIO.write(dest, "png", scrFile); FileUtils.copyFile(scrFile, new File(screenshotPathAndName)); } catch(Exception e) { e.printStackTrace(); } }
@Override public void addAugmentedImages(List<BufferedImage> images) { int l = images.size(); for (int i = 0; i < l; i++) { BufferedImage im = images.get(i); for (int j = 0; j < crops; j++) { images.add(im.getSubimage(random.nextInt(im.getWidth() - cropX), random.nextInt(im.getHeight() - cropY), cropX, cropY)); } } images.subList(0, l).clear(); }
private BufferedImage cutTopBottom(BufferedImage origin, PlateVerticalGraph graph) { graph.applyProbabilityDistributor(new Graph.ProbabilityDistributor(0f, 0f, 2, 2)); Peak p = graph.findPeak(3).get(0); return origin.getSubimage(0, p.getLeft(), getImage().getWidth(), p.getDiff()); }
@Override public void addAugmentedImages(List<BufferedImage> images) { int l = images.size(); for (int i = 0; i < l; i++) { BufferedImage source = images.get(i); for (int x = 0; x <= source.getWidth() - width; x += strideX) { for (int y = 0; y <= source.getHeight() - height; y += strideY) { images.add(source.getSubimage(x, y, width, height)); } } } images.subList(0, l).clear(); }
@Override final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormatOption) throws IOException { final BufferedImage im = createImage(); final ImageData imageData = new ImageDataSimple(im.getWidth(), (int) maxYpos); PngIO.write(im.getSubimage(0, 0, imageData.getWidth(), imageData.getHeight()), os, 96); return imageData; }
public BufferedImage getCroppedImage() throws IOException { //out if croppedArea == 0 or file is null Rectangle goal = new Rectangle( (int)this.getCropAreaWidth(), (int) this.getCropAreaHeight()); //Then intersect it with the dimensions of your image: Rectangle clip = goal.intersection(new Rectangle(originalFile.getWidth(), originalFile.getHeight())); //Now, clip corresponds to the portion of bi that will fit within your goal. In this case 100 x50. //Now get the subImage using the value of clip. BufferedImage clippedImg = originalFile.getSubimage(clip.x, clip.y, clip.width, clip.height); return clippedImg; }
@Override public List<BufferedImage> getNextRawImages() { if (images == null) { images = new BufferedImage[properties.getImagesBulkSize()]; } IntStream stream = IntStream.range(0, properties.getImagesBulkSize()); stream.forEach(i -> { if (sourceImages.get(currentImage).getWidth() - width > currentX) { currentX++; } else if (sourceImages.get(currentImage).getHeight() - height > currentY) { currentY++; currentX = 0; } else { currentImage = (currentImage + 1) % sourceImages.size(); currentY = currentX = 0; } images[i] = sourceImages.get(currentImage).getSubimage(currentX, currentY, width, height); }); return Arrays.asList(images); }
switch (resizeType) { case SMALLEST_DIMENSION_RECT: if (input.getWidth() < input.getHeight()) targetHeight = (int) (input.getHeight() / ((float) input.getWidth()) * smallestDimension); } else targetWidth = (int) (input.getWidth() / ((float) input.getHeight()) * smallestDimension); targetHeight = smallestDimension; if (input.getWidth() < input.getHeight()) input = input.getSubimage(0, (input.getHeight() - input.getWidth()) / 2, input.getWidth(), input.getWidth()); } else input = input.getSubimage((input.getWidth() - input.getHeight()) / 2, 0, input.getHeight(), input.getHeight());
/** * 剪切 * * @param srcImageFile 原图 * @param destImageFile 存放的目标位置 * @param left 起始点:左 * @param top 起始点:上 * @param width 宽 * @param height 高 */ public static void crop(String srcImageFile, String destImageFile, int left, int top, int width, int height) { if (notImageExtName(srcImageFile)) { throw new IllegalArgumentException("只支持如下几种图片格式:jpg、jpeg、png、bmp"); } try { BufferedImage bi = ImageIO.read(new File(srcImageFile)); width = Math.min(width, bi.getWidth()); height = Math.min(height, bi.getHeight()); if (width <= 0) width = bi.getWidth(); if (height <= 0) height = bi.getHeight(); left = Math.min(Math.max(0, left), bi.getWidth() - width); top = Math.min(Math.max(0, top), bi.getHeight() - height); BufferedImage subimage = bi.getSubimage(left, top, width, height); BufferedImage resizeImage = resize(subimage, 200, 200); save(resizeImage, destImageFile); } catch (Exception e) { log.error(e.toString(), e); } }
if ( avatar.getWidth() <= targetDimension && avatar.getHeight() <= targetDimension ) Log.debug( "Original image dimension ({}x{}) is within acceptable bounds ({}x{}). No need to resize.", new Object[] { avatar.getWidth(), avatar.getHeight(), targetDimension, targetDimension }); return null; Log.debug( "Original image is " + avatar.getWidth() + "x" + avatar.getHeight() + " pixels" ); avatar = avatar.getSubimage( x, y, targetWidth, targetHeight );