You are on page 1of 1

Get Started Themes Templates Resources v12.0.

0-SNAPSHOT

PhotoCam
Search by name...
 SERVER API

Responsive  CLIENT API


It is possible to set a specific device, like a USB camera or a different onboard camera, to retrieve images. Note that, in mobile devices, usually "user" stands for the front camera and
FullScreen "environment" stands for the rear camera.

AutoPlay

Caption

Media

PhotoCam

PhotoCam

Device Selection Capture

Switch

Video

Select device
FILE

Upload

Download

deviceSelection.xhtml PhotoCamView.java
DRAGDROP

Draggable
1 @Named
DataView 2 @ViewScoped
3 public class PhotoCamView implements Serializable {
DataTable 4
5 private String filename;
Custom
6
7 private String getRandomImageName() {
8 int i = (int) (Math.random() * 10000000);
9
10 return String.valueOf(i);
11 }
12
13 public String getFilename() {
14 return filename;
15 }
16
17 public void oncapture(CaptureEvent captureEvent) {
18 filename = getRandomImageName();
19 byte[] data = captureEvent.getData();
20
21 ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
22 String newFileName = externalContext.getRealPath("") + File.separator + "resources" + File.separator + "demo"
23 + File.separator + "images" + File.separator + "photocam" + File.separator + filename + ".jpeg";
24
25 FileImageOutputStream imageOutput;
26 try {
27 imageOutput = new FileImageOutputStream(new File(newFileName));
28 imageOutput.write(data, 0, data.length);
29 imageOutput.close();
30 }
31 catch (IOException e) {
32 throw new FacesException("Error in writing captured image.", e);
33 }
34 }
35 }

PrimeFaces 12.0.0 by PrimeTek   

You might also like