Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.czollmann.hochzeit.application.fxml;
- import java.io.File;
- import java.io.IOException;
- import javafx.application.Platform;
- import javafx.concurrent.Task;
- import javafx.embed.swing.SwingFXUtils;
- import javafx.event.ActionEvent;
- import javafx.scene.image.Image;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import com.czollmann.hochzeit.SettingsEnum;
- import com.czollmann.hochzeit.SettingsUtil;
- import com.czollmann.hochzeit.model.ImageModel;
- import edsdk.api.CanonCamera;
- import edsdk.utils.CanonConstants.EdsImageQuality;
- import edsdk.utils.CanonConstants.EdsSaveTo;
- public class CaptureCanonController extends CaptureController {
- private final static Logger logger = LoggerFactory
- .getLogger(CaptureCanonController.class);
- private CanonCamera camera = null;
- private Thread webcamUpdateThread = null;
- private boolean stopCamera = false;
- @Override
- protected void initCamera() {
- camera = new CanonCamera();
- if (camera != null) {
- if (camera.openSession()) {
- if (camera.beginLiveView()) {
- startStream();
- } else {
- logger.error("no live view");
- }
- } else {
- logger.error("no open session");
- }
- } else {
- logger.error("no camera");
- }
- }
- @Override
- protected void startStream() {
- stopCamera = false;
- Task<Void> task = new Task<Void>() {
- @Override
- protected Void call() throws Exception {
- while (!stopCamera) {
- try {
- if ((grabbedImage = camera.downloadLiveView()) != null) {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- final Image mainImage = SwingFXUtils
- .toFXImage(grabbedImage, null);
- imageProperty.set(mainImage);
- }
- });
- grabbedImage.flush();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- };
- webcamUpdateThread = new Thread(task);
- webcamUpdateThread.setDaemon(true);
- webcamUpdateThread.start();
- webcamImage.imageProperty().bind(imageProperty);
- webcamImage.setFitWidth(captureContainer.getWidth());
- webcamImage.setFitHeight(captureContainer.getHeight());
- }
- @Override
- public void stopCamera(ActionEvent event) {
- stopCamera = true;
- }
- @Override
- public void startCamera(ActionEvent event) {
- stopCamera = false;
- startStream();
- }
- @Override
- protected ImageModel captureImage() {
- stopCamera = true;
- camera.endLiveView();
- try {
- File destinationFolder = new File(
- SettingsUtil
- .getProperty(SettingsEnum.CAPTURE_SAVE_LOCATION));
- //ISSUE HERE
- camera.setImageQuality(EdsImageQuality.EdsImageQuality_LR);
- //ISSUE HERE
- final File[] photos = camera.shoot(EdsSaveTo.kEdsSaveTo_Host,
- Integer.MAX_VALUE, destinationFolder);
- if (photos != null) {
- File photo = getCapturedJpeg(photos);
- if (photo != null) {
- ImageModel imageModel = new ImageModel(photo);
- if (imageModel != null) {
- return imageModel;
- }
- }
- }
- } catch (Exception e) {
- logger.error("could not capture", e);
- } finally {
- camera.closeSession();
- }
- return null;
- }
- private File getCapturedJpeg(final File[] photos) throws IOException {
- File photo = null;
- if (photos.length == 2) {
- if (photos[1].getCanonicalPath().toLowerCase().endsWith(".jpg")) {
- photo = photos[1];
- } else {
- photo = photos[0];
- }
- } else {
- photo = photos[0];
- }
- return photo;
- }
- @Override
- public void close() {
- stopCamera = true;
- camera.closeSession();
- CanonCamera.close();
- super.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement