Skip to content

Commit

Permalink
#19 create initial helper for rendering diagrams using java2d
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Oct 27, 2018
1 parent a4bd706 commit 0e41d77
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.ephyra.acropolis.report.impl.render

import java.awt.Color
import java.awt.Graphics2D
import java.awt.image.BufferedImage
import java.awt.image.BufferedImage.TYPE_INT_RGB
import java.io.File
import javax.imageio.ImageIO

class DiagramRenderer(
private val width: Int,

private val height: Int
) : AutoCloseable {
private val targetImg: BufferedImage = BufferedImage(width, height, TYPE_INT_RGB)
private val target: Graphics2D

init {
target = targetImg.createGraphics()

target.color = Color.WHITE
target.fillRect(0, 0, width, height)
}

fun addImage(positionX: Int, positionY: Int, source: File) {
val img = ImageIO.read(source)
target.drawImage(img, positionX, positionY, img.width, img.height, null)
}

fun export(outFile: File) {
ImageIO.write(targetImg, outFile.extension, outFile)
}

override fun close() {
target.dispose()
}
}

0 comments on commit 0e41d77

Please sign in to comment.