Exemple #1
0
  public void oncapture(CaptureEvent captureEvent) {
    String photo = getRandomImageName();
    this.photos.add(0, photo);
    byte[] data = captureEvent.getData();

    ServletContext servletContext =
        (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
    String newFileName =
        servletContext.getRealPath("")
            + File.separator
            + "photocam"
            + File.separator
            + photo
            + ".png";

    FileImageOutputStream imageOutput;
    try {
      imageOutput = new FileImageOutputStream(new File(newFileName));
      imageOutput.write(data, 0, data.length);
      imageOutput.close();

    } catch (Exception e) {
      throw new FacesException("Error in writing captured image.");
    }
  }
  public void capiturarImagemWebCam(CaptureEvent captureEvent, String enderecoComNome) {
    byte[] data = captureEvent.getData();

    String arquivo = enderecoComNome + ".png";

    FileImageOutputStream imageOutput;
    try {
      imageOutput = new FileImageOutputStream(new File(arquivo));
      imageOutput.write(data, 0, data.length);
      imageOutput.close();
    } catch (IOException e) {
      throw new FacesException("Erro ao salvar Imagem.", e);
    }
  }