Created
February 11, 2021 20:23
-
-
Save eliasnogueira/bd67f8974d330febd21800b1b80aa124 to your computer and use it in GitHub Desktop.
Generates an image based on a screenshot and Mobile element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The complete code can be found at https://github.com/eliasnogueira/appium-read-qrcode