Skip to content

Instantly share code, notes, and snippets.

@rladstaetter
Created April 7, 2013 19:04
Show Gist options
  • Select an option

  • Save rladstaetter/5331985 to your computer and use it in GitHub Desktop.

Select an option

Save rladstaetter/5331985 to your computer and use it in GitHub Desktop.
A small JavaFX application which shows an image taken by the isight camera using imagesnap
package net.ladstatt.apps.isight
import java.io.InputStream
import javafx.application.Application
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.stage.Stage
object HelloIsight {
def main(args: Array[String]): Unit = {
Application.launch(classOf[HelloIsight], args: _*)
}
}
class HelloIsight extends javafx.application.Application {
// this can get more complicated if you use a "native" approach
// using a jni based solution
// see http://iharder.sourceforge.net/current/macosx/imagesnap/
def snapIt: InputStream = {
val runtime = Runtime.getRuntime()
val process = runtime.exec(Array("/opt/local/bin/imagesnap", "-"))
process.getInputStream()
}
override def start(stage: Stage): Unit = {
stage.setTitle("Webcam snapshot")
val group = new Group
val imageView = new ImageView(new Image(snapIt))
group.getChildren.add(imageView)
val scene = new Scene(group)
stage.setScene(scene)
stage.show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment