Advertisement
Guest User

50D Issue

a guest
May 10th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. package com.czollmann.hochzeit.application.fxml;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import javafx.application.Platform;
  7. import javafx.concurrent.Task;
  8. import javafx.embed.swing.SwingFXUtils;
  9. import javafx.event.ActionEvent;
  10. import javafx.scene.image.Image;
  11.  
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14.  
  15. import com.czollmann.hochzeit.SettingsEnum;
  16. import com.czollmann.hochzeit.SettingsUtil;
  17. import com.czollmann.hochzeit.model.ImageModel;
  18.  
  19. import edsdk.api.CanonCamera;
  20. import edsdk.utils.CanonConstants.EdsImageQuality;
  21. import edsdk.utils.CanonConstants.EdsSaveTo;
  22.  
  23. public class CaptureCanonController extends CaptureController {
  24. private final static Logger logger = LoggerFactory
  25. .getLogger(CaptureCanonController.class);
  26. private CanonCamera camera = null;
  27. private Thread webcamUpdateThread = null;
  28. private boolean stopCamera = false;
  29.  
  30. @Override
  31. protected void initCamera() {
  32. camera = new CanonCamera();
  33. if (camera != null) {
  34. if (camera.openSession()) {
  35. if (camera.beginLiveView()) {
  36. startStream();
  37. } else {
  38. logger.error("no live view");
  39. }
  40. } else {
  41. logger.error("no open session");
  42. }
  43. } else {
  44. logger.error("no camera");
  45. }
  46. }
  47.  
  48. @Override
  49. protected void startStream() {
  50. stopCamera = false;
  51. Task<Void> task = new Task<Void>() {
  52. @Override
  53. protected Void call() throws Exception {
  54. while (!stopCamera) {
  55. try {
  56. if ((grabbedImage = camera.downloadLiveView()) != null) {
  57. Platform.runLater(new Runnable() {
  58. @Override
  59. public void run() {
  60. final Image mainImage = SwingFXUtils
  61. .toFXImage(grabbedImage, null);
  62. imageProperty.set(mainImage);
  63. }
  64. });
  65. grabbedImage.flush();
  66. }
  67. } catch (Exception e) {
  68. e.printStackTrace();
  69. }
  70. }
  71. return null;
  72. }
  73. };
  74. webcamUpdateThread = new Thread(task);
  75. webcamUpdateThread.setDaemon(true);
  76. webcamUpdateThread.start();
  77. webcamImage.imageProperty().bind(imageProperty);
  78. webcamImage.setFitWidth(captureContainer.getWidth());
  79. webcamImage.setFitHeight(captureContainer.getHeight());
  80. }
  81.  
  82. @Override
  83. public void stopCamera(ActionEvent event) {
  84. stopCamera = true;
  85. }
  86.  
  87. @Override
  88. public void startCamera(ActionEvent event) {
  89. stopCamera = false;
  90. startStream();
  91. }
  92.  
  93. @Override
  94. protected ImageModel captureImage() {
  95. stopCamera = true;
  96. camera.endLiveView();
  97. try {
  98. File destinationFolder = new File(
  99. SettingsUtil
  100. .getProperty(SettingsEnum.CAPTURE_SAVE_LOCATION));
  101. //ISSUE HERE
  102. camera.setImageQuality(EdsImageQuality.EdsImageQuality_LR);
  103. //ISSUE HERE
  104. final File[] photos = camera.shoot(EdsSaveTo.kEdsSaveTo_Host,
  105. Integer.MAX_VALUE, destinationFolder);
  106. if (photos != null) {
  107. File photo = getCapturedJpeg(photos);
  108. if (photo != null) {
  109. ImageModel imageModel = new ImageModel(photo);
  110. if (imageModel != null) {
  111. return imageModel;
  112. }
  113. }
  114. }
  115. } catch (Exception e) {
  116. logger.error("could not capture", e);
  117. } finally {
  118. camera.closeSession();
  119. }
  120. return null;
  121. }
  122.  
  123. private File getCapturedJpeg(final File[] photos) throws IOException {
  124. File photo = null;
  125. if (photos.length == 2) {
  126. if (photos[1].getCanonicalPath().toLowerCase().endsWith(".jpg")) {
  127. photo = photos[1];
  128. } else {
  129. photo = photos[0];
  130. }
  131. } else {
  132. photo = photos[0];
  133. }
  134. return photo;
  135. }
  136.  
  137. @Override
  138. public void close() {
  139. stopCamera = true;
  140. camera.closeSession();
  141. CanonCamera.close();
  142. super.close();
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement