Skip to content

Instantly share code, notes, and snippets.

@samlucax
Created August 21, 2017 16:46
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 samlucax/255ebc94b6f3361b4d8c81b63a70d612 to your computer and use it in GitHub Desktop.
Save samlucax/255ebc94b6f3361b4d8c81b63a70d612 to your computer and use it in GitHub Desktop.
Automatizando validação de códigos de barras com API Zxing
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage imagem = ImageIO.read(screenshot);
//Se você prefere uma imagem só do trecho onde o código de barras aparece, pode realizar um corte na imagem, da seguinte forma:
//Pegando a posicao do elemento
Point posicao = codigoDeBarras.getLocation();
//Pegando altura e largura do elemento
int larguraElemento = codigoDeBarras.getSize().getWidth();int alturaElemento = codigoDeBarras.getSize().getHeight();
//Recortando a imagem
BufferedImage imagemCortada = imagem.getSubImage(point.getX(), point.getY(), eleWidth, eleHeight);
ImageIO.write(imagemCortada, "jpg", imagem);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment