Skip to content

Instantly share code, notes, and snippets.

Embed
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 = ImageIO.read(screenshot);
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;
}
@eliasnogueira

This comment has been minimized.

Copy link
Owner Author

@eliasnogueira eliasnogueira commented Feb 11, 2021

The complete code can be found at https://github.com/eliasnogueira/appium-read-qrcode

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