How to use stitchImages method of org.fluentlenium.utils.ImageUtils class

Best FluentLenium code snippet using org.fluentlenium.utils.ImageUtils.stitchImages

Source:ImageUtils.java Github

copy

Full Screen

...44 try {45 BufferedImage screenshotImage = ImageIO.read(scrFile);46 BufferedImage alertImage = generateAlertImageWithLogo(alertText, screenshotImage.getWidth());47 FileUtils.deleteQuietly(scrFile);48 return toByteArray(stitchImages(screenshotImage, alertImage, false));49 } catch (IOException e) {50 throw new ScreenshotNotCreatedException("Error while reading screenshot file.", e);51 }52 }53 /**54 * Converts the file referenced by the argument file name to a {@link BufferedImage}.55 *56 * @param fileName the name of the file to convert57 * @return the converted BufferedImage58 * @throws NoSuchFileException if the argument file cannot be found59 * @throws ScreenshotNotCreatedException if a problem occurred during image conversion60 */61 public static BufferedImage toBufferedImage(String fileName) throws IOException {62 InputStream is = Files.newInputStream(Paths.get(fileName));63 try {64 BufferedImage image = ImageIO.read(is);65 is.close();66 return image;67 } catch (IOException e) {68 throw new ScreenshotNotCreatedException(ERROR_WHILE_CONVERTING_IMAGE, e);69 }70 }71 private byte[] toByteArray(BufferedImage image) {72 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();73 try {74 ImageIO.write(image, "png", byteArrayOutputStream);75 return byteArrayOutputStream.toByteArray();76 } catch (IOException e) {77 throw new ScreenshotNotCreatedException(ERROR_WHILE_CONVERTING_IMAGE, e);78 }79 }80 private BufferedImage stitchImages(BufferedImage image1, BufferedImage image2, boolean asOverlay) {81 if (asOverlay) {82 int x = Math.max(image1.getWidth(), image2.getWidth());83 int y = Math.max(image1.getHeight(), image2.getHeight());84 BufferedImage stitchedImage = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);85 Graphics g = stitchedImage.getGraphics();86 g.drawImage(image1, 0, 0, null);87 g.drawImage(image2, image1.getWidth() - image2.getWidth(), image1.getHeight() - image2.getHeight(), null);88 return stitchedImage;89 } else {90 BufferedImage stitchedImage = new BufferedImage(image1.getWidth(), image1.getHeight() + image2.getHeight(),91 BufferedImage.TYPE_INT_RGB);92 Graphics graphics = stitchedImage.getGraphics();93 graphics.drawImage(image1, 0, 0, null);94 graphics.drawImage(image2, 0, image1.getHeight(), null);95 graphics.setColor(Color.BLACK);96 graphics.drawLine(0, image1.getHeight(), image1.getWidth(), image1.getHeight());97 return stitchedImage;98 }99 }100 private BufferedImage generateAlertImageWithLogo(String alertText, int screenshotWidth) throws IOException {101 BufferedImage alertImage = generateImageWithText(alertText, screenshotWidth, 200);102 BufferedImage logo = toBufferedImage(ImageUtils.class.getResource("/fl_logo.png").getPath());103 return stitchImages(alertImage, logo, true);104 }105 private BufferedImage generateImageWithText(String text, int width, int height) {106 BufferedImage alertImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);107 Graphics graphics = alertImage.getGraphics();108 graphics.setColor(new Color(220, 218, 218));109 graphics.fillRect(0, 0, width, height);110 graphics.setColor(Color.BLACK);111 graphics.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));112 drawStringMultiLine(graphics, text, (width - 200) - 10);113 return alertImage;114 }115 private void drawStringMultiLine(Graphics g, String text, int lineWidth) {116 FontMetrics m = g.getFontMetrics();117 int xPosition = 10;...

Full Screen

Full Screen

stitchImages

Using AI Code Generation

copy

Full Screen

1ImageUtils.stitchImages("path/to/image1.png", "path/to/image2.png", "path/to/image3.png", "path/to/image4.png", "path/to/image5.png", "path/to/image6.png");2ImageUtils.stitchImages("path/to/image1.png", "path/to/image2.png", "path/to/image3.png", "path/to/image4.png", "path/to/image5.png", "path/to/image6.png", "path/to/image7.png");3ImageUtils.stitchImages("path/to/image1.png", "path/to/image2.png", "path/to/image3.png", "path/to/image4.png", "path/to/image5.png", "path/to/image6.png", "path/to/image7.png", "path/to/image8.png");4ImageUtils.stitchImages("path/to/image1.png", "path/to/image2.png", "path/to/image3.png", "path/to/image4.png", "path/to/image5.png", "path/to/image6.png", "path/to/image7.png", "path/to/image8.png", "path/to/image9.png");5ImageUtils.stitchImages("path/to/image1.png", "path/to/image2.png", "path/to/image3.png", "path/to/image4.png", "path/to/image5.png", "path/to/image6.png", "path/to/image7.png", "path/to/image8.png", "path/to/image9.png", "path/to/image10.png");6ImageUtils.stitchImages("path/to/image1.png", "path/to/image2.png", "path/to/image3.png", "path/to/image4.png", "path/to/image5.png", "path/to/image6.png", "path/to/image7.png", "path/to/image8.png", "path/to/image9.png", "path/to/image10.png", "path/to/image11.png");

Full Screen

Full Screen

stitchImages

Using AI Code Generation

copy

Full Screen

1ImageUtils imageUtils = new ImageUtils();2BufferedImage mergedImage = imageUtils.stitchImages(screenshot, logo);3imageUtils.saveImage(mergedImage, "merged.png");4byte[] mergedImageBytes = imageUtils.toByteArray(mergedImage);5InputStream mergedImageStream = imageUtils.toInputStream(mergedImage);6imageUtils.saveImage(mergedImage, "merged.png");7byte[] mergedImageBytes = imageUtils.toByteArray(mergedImage);8InputStream mergedImageStream = imageUtils.toInputStream(mergedImage);9imageUtils.saveImage(mergedImage, "merged.png");10byte[] mergedImageBytes = imageUtils.toByteArray(mergedImage);11InputStream mergedImageStream = imageUtils.toInputStream(mergedImage);12imageUtils.saveImage(mergedImage, "merged.png");13byte[] mergedImageBytes = imageUtils.toByteArray(mergedImage);14InputStream mergedImageStream = imageUtils.toInputStream(mergedImage);15imageUtils.saveImage(mergedImage, "merged.png");16byte[] mergedImageBytes = imageUtils.toByteArray(mergedImage);17InputStream mergedImageStream = imageUtils.toInputStream(mergedImage);18imageUtils.saveImage(mergedImage, "merged.png");19byte[] mergedImageBytes = imageUtils.toByteArray(mergedImage);20InputStream mergedImageStream = imageUtils.toInputStream(mergedImage);21imageUtils.saveImage(mergedImage, "merged.png");

Full Screen

Full Screen

stitchImages

Using AI Code Generation

copy

Full Screen

1ImageUtils stitchImages(List<String> images, String targetImage, int horizontalPadding, int verticalPadding) throws IOException2List<String> imagePaths = new ArrayList<>();3imagePaths.add("image1.png");4imagePaths.add("image2.png");5imagePaths.add("image3.png");6imagePaths.add("image4.png");7ImageUtils.stitchImages(imagePaths, "stitched.png", 20, 20);8File getScreenshot() throws IOException9File screenshot = getScreenshot();10File getScreenshot(String targetImage) throws IOException11File screenshot = getScreenshot("screenshot.png");12File getScreenshot(String targetImage, int width, int height) throws IOException13File screenshot = getScreenshot("screenshot.png", 300, 300);14File getScreenshot(int width, int height) throws IOException

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run FluentLenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful