Last active
October 22, 2020 03:51
-
-
Save ktgw0316/67cadfcfe3ba6db5c843d80a53a85a25 to your computer and use it in GitHub Desktop.
Eclipse Imagen demo in Kotlin
This file contains hidden or 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
| package org.eclipse.imagen.demo | |
| import org.eclipse.imagen.Interpolation | |
| import org.eclipse.imagen.JAI | |
| import org.eclipse.imagen.widget.ScrollingImagePanel | |
| import java.awt.image.RenderedImage | |
| import java.awt.image.renderable.ParameterBlock | |
| import java.io.File | |
| import java.io.IOException | |
| import javax.imageio.ImageIO | |
| import javax.swing.JFrame | |
| import javax.swing.SwingUtilities | |
| import javax.swing.WindowConstants | |
| // Kotlin extension functions | |
| fun RenderedImage.scale(scaleX: Float, scaleY: Float, transX: Float = 0f, transY: Float = 0f, | |
| interp: Interpolation = Interpolation.getInstance( | |
| Interpolation.INTERP_BILINEAR)) : RenderedImage { | |
| val pb = ParameterBlock() | |
| .addSource(this) | |
| .add(scaleX) | |
| .add(scaleY) | |
| .add(transX) | |
| .add(transY) | |
| .add(interp) | |
| return JAI.create("scale", pb) | |
| } | |
| fun ScrollingImagePanel(img: RenderedImage) = ScrollingImagePanel(img, img.width, img.height) | |
| object scratch_1 { | |
| @Throws(IOException::class) | |
| @JvmStatic | |
| fun main(args: Array<String>) { | |
| val image1 = ImageIO.read(File(args[0])) | |
| val interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC) | |
| val image2 = image1.scale(1.2f, 1.2f, interp = interp) | |
| SwingUtilities.invokeLater { | |
| JFrame("ImageN Builder Sample Program").apply { | |
| defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE; | |
| add(ScrollingImagePanel(image2)) | |
| pack() | |
| isVisible = true | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment