Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generates an image based on a screenshot and Mobile element
private BufferedImage generateImage(MobileElement element, File screenshot) {
BufferedImage qrCodeImage = null;
try {
BufferedImage fullImage =;
Point imageLocation = element.getLocation();
int qrCodeImageWidth = element.getSize().getWidth();
int qrCodeImageHeight = element.getSize().getHeight();
int pointXPosition = imageLocation.getX();
int pointYPosition = imageLocation.getY();
qrCodeImage = fullImage.getSubimage(pointXPosition, pointYPosition, qrCodeImageWidth, qrCodeImageHeight);
ImageIO.write(qrCodeImage, "png", screenshot);
} catch (IOException e) {
log.error("Problem during the image generation", e);
return qrCodeImage;
Copy link

eliasnogueira commented Feb 11, 2021

The complete code can be found at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment