Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added showcase for writing an image to a file
- Loading branch information
Showing
2 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
showcase-jvm/src/main/scala/doctus/jvm/ShowcaseTemplateJvmFileStillImage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package doctus.jvm | ||
|
||
import java.io.File | ||
import javafx.application.Application | ||
import javafx.embed.swing.SwingFXUtils | ||
import javafx.scene._ | ||
import javafx.scene.canvas.Canvas | ||
import javafx.stage.Stage | ||
import javax.imageio.ImageIO | ||
|
||
import doctus.core._ | ||
import doctus.core.template.DoctusTemplateController | ||
|
||
object ShowcaseTemplateJvmFileStillImage extends App { | ||
|
||
Application.launch(classOf[FxApp], args: _*) | ||
|
||
class FxApp extends Application { | ||
|
||
val homeDir = new File(System.getProperty("user.home")) | ||
val pngFile = new File(homeDir, "ShowcaseTemplateJvmFileStillImage.png") | ||
|
||
override def start(stage1: Stage) { | ||
|
||
val width = 3000 | ||
val height = 2000 | ||
|
||
val canvas = new Canvas(width, height) | ||
|
||
val doctCanvas = DoctusTemplateCanvasFx(canvas) | ||
val doctSched = DoctusSchedulerJvm | ||
|
||
val grp = new Group() | ||
grp.getChildren.add(canvas) | ||
|
||
// Start the controller | ||
val templ = DoctusTemplateStillImage(doctCanvas) | ||
DoctusTemplateController(templ, doctSched, doctCanvas) | ||
doctCanvas.repaint() | ||
|
||
val wi = grp.snapshot(new SnapshotParameters(), null) | ||
require(wi != null) | ||
val bi = SwingFXUtils.fromFXImage(wi, null) | ||
require(bi != null) | ||
ImageIO.write(bi, "png", pngFile) | ||
|
||
println("wrote image to '%s'" format pngFile) | ||
System.exit(0) | ||
|
||
} | ||
} | ||
|
||
} | ||
|