Professional Documents
Culture Documents
0-SNAPSHOT
PhotoCam
Search by name...
SERVER API
AutoPlay
Caption
Media
PhotoCam
PhotoCam
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 }