Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Created February 11, 2021 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/bd67f8974d330febd21800b1b80aa124 to your computer and use it in GitHub Desktop.
Save eliasnogueira/bd67f8974d330febd21800b1b80aa124 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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