Codetown ::: a software developer's community
Welcome to Kotlin Thursdays and Happy Halloween! This week, we will be exploring image processing in Kotlin. If you have used applications like Instagram, Snapchat, or even Photoshop, you may already be familiar with image processing and not even know it!
Image processing is not specific to Kotlin, but playing with images can help us think about how algorithms are applied in a 2-D matrix and develop computational thinking. Once we get the basics down, the world is your oyster!
We will be leveraging TornadoFX, a JavaFX framework written in Kotlin for native desktop development. Let's get started setting up our TornadoFX project!
Think of these resources as supplemental if you happen to be more curious. We always encourage looking into documentation for things you use!
In the spirit of open-source languages and resources, it's only a natural choice to use IntelliJ Community edition.
First, make sure you're set up with TornadoFX on your IntelliJ. If you don't have IntelliJ, you can download it for free here!
Choose any photo, or take this one below and save it in a resource folder in your project!
1. On IntelliJ, go to Preferences > Plugins and make sure Kotlin and TornadoFX is installed.
2. General consensus amongst TornadoFXers is that Maven is easier to user - and Maven is great as long as you do not require lot of dependencies for your project. Otherwise, it's recommended to use Gradle. For the scope of this project, it is not necessary to understand how to use either of build tools, but don't hesitate to leave comments/questions/concerns here if you happen to run into any trouble throughout the project. Let's go ahead and select tornadofx-maven-project, which will nicely set up much of our project immediately.
3. If you haven't already, go to your pom.xml file and check to see if your kotlin version is updated. As of November 1st, 2018, the latest Kotlin version is 1.3.0, but feel free to refer to your plugins to check versioning. If you don't have your changes imported automatically, hit "Import Changes". If it builds successfully, you should be good to go!
In your source code, you'll notice a brief hierarchy - within com.example.demo, you have an app folder which stores the files MyApp and Styles, and you also have a view folder which contains the MainView.
App
To create a TornadoFX application, you must have at least one class that extendsApp. An App is the entry point to the application and specifies the initial View.
package com.example.demo.app
import com.example.demo.view.MainView
import tornadofx.App
class MyApp: App(MainView::class, Styles::class)
Stylesheet
Traditionally in JavaFX, a stylesheet is defined in a plain CSS text file included in the project. However, TornadoFX allows creating stylesheets with pure Kotlin code. This has the benefits of compilation checks, auto-completion, and other perks that come with statically-typed code. A companion object is declared to hold class-level properties that can easily be retrieved throughout the app. Then, the init() block is used to apply styling to classes. For more on styling, see Type-Safe CSS.
package com.example.demo.app
import ...
class Styles: Stylesheet( ) {
companion object {
val heading by cssclass()
}
init {
label and heading {
padding = box(10.px)
fontSize = box(20.px)
fontWeight = FontWeight.BOLD
}
}
View
A View contains the display logic as well as a layout of Nodes. TornadoFX provides a builder syntax that will streamline your UI code. These builders allow us to express the UI as a hierarchical structure, which enables you to visualize the resulting UI easily. Note that all builders are written in lowercase, so as not to confuse them with manual instantiation of the UI element classes.
We're going to modify the code to render our rooster image. Always write a little code and check if it works. You don't want to keep writing something that is broken in the first place!
package com.example.demo.app
import ...
class MainView: View("I am a chicken") {
override val root = hbox {
imageview("rooster.png")
hboxConstraints {
prefWidth = 640.0
prefHeight = 427.0
}
}
}
According to TornadoFX documentation on images, it doesn't appear much different from JavaFX Images and ImageViews, but a TornadoFX allows far less syntax in programming over JavaFX:
Image image = new Image(new FileInputStream("path of image"));
ImageView imageView = new ImageView(image);
imageView.setX(50);
imageView.setY(25);
imageView.setFitHeight(455);
imageView.setFitWidth(500);
Group root = new Group(imageView);
Scene scene = new Scene(root, 600, 500);
}
Java implementation
imageview("tornadofx.jpg")
scaleX = . 50
scaleY = . 50
}
Kotlin implementation
Let's click run and make sure we're able to render the method!
Noice.
Now that we've figured out how to render an image, we're going to talk about how we can access pixels in an image. Images are essentially 2-dimensional matrixes in which we are able to iteratively access an image's pixel value by row and column. We then can apply operations to those pixels and alter the image as a whole.
We can use JavaFX's WritableImage to allow a canvas while storing the URI as an Image. This way, we are given access to PixelReader and PixelWriter. Super convenient!
package com.example.demo.app
import ...
class MainView: View("I am a chicken") {
private val image = Image("rooster.png")
private val width = image.width.toInt( )
private val height = image.width.toInt( )
private val width = WritableImage(image.pixelReader width, height)
override val root = hbox {
imageview(wImage).apply {
makeDuller(wImage)
makeDuller(wImage)
makeDuller(wImage)
}
hboxConstraints {
prefWidth = 640.0
prefHeight = 427.0
}
}
private fun makeDuller = (image: WritableImage) {
val pixelWriter = image.pixelWriter
for ( x in 0 until width) {
for ( y in 0 until height) {
val color = image.pixelReader.getColor(x, y)
pixelWriter.setColor(x, y, color.desaturate( ))
}
}
}
}
}
We used Kotlin's apply three times because we wanted to make sure we could REALLY see the difference. In Kotlin, you can use the call apply where the scope calls this (itself) as the receiver and the result is the object with applied functions.
In the function makeDuller, we access the color of an individual pixel that we read and subsequently use pixelWriter to set that pixel a different color. Double noice.
We've figured out how to grab individual pixels of an image and manipulate them. Next week, we'll be going over pixel math and using math pixel to create our own image processing filters. Stay tuned!
Having a blast? Check out part 2 of this series!
Tags:
Codetown is a social network. It's got blogs, forums, groups, personal pages and more! You might think of Codetown as a funky camper van with lots of compartments for your stuff and a great multimedia system, too! Best of all, Codetown has room for all of your friends.
Created by Michael Levin Dec 18, 2008 at 6:56pm. Last updated by Michael Levin May 4, 2018.
Check out the Codetown Jobs group.

Google Research unveiled TurboQuant, a novel quantization algorithm that compresses large language models’ Key-Value caches by up to 6x. With 3.5-bit compression, near-zero accuracy loss, and no retraining needed, it allows developers to run massive context windows on significantly more modest hardware than previously required. Early community benchmarks confirm significant efficiency gains.
By Bruno Couriol
Celine Pypaert discusses the ubiquitous nature of open-source software and shares a blueprint for securing modern applications. She explains how to prioritize high-risk vulnerabilities using exploitability data, the role of Software Bill of Materials (SBOM), and the importance of bridging the gap between DevOps and Security through clear accountability and automated governance.
By Celine Pypaert
Zendesk argues that GenAI shifts the bottleneck in software delivery from writing code to “absorption capacity”, which is the organisation’s ability to define problems clearly, integrate changes into the wider system, and turn implementation into reliable value. As code becomes abundant, architectural coherence, review capacity, and delivery flow become the main constraints.
By Eran Stiller
Anthropic researcher Nicholas Carlini used Claude Code to find a remotely exploitable heap buffer overflow in the Linux kernel's NFS driver, undiscovered for 23 years. Five kernel vulnerabilities have been confirmed so far. Linux kernel maintainers report that AI bug reports have recently shifted from slop to legitimate findings, with security lists now receiving 5-10 valid reports daily.
By Steef-Jan Wiggers
At Lead Bank, synchronous telemetry flushing caused intermittent exporter stalls to become user-facing 504 gateway timeouts. By leveraging AWS Lambda's Extensions API and goroutine chaining in Go, flush work is moved off the response path, returning responses immediately while preserving full observability without telemetry loss.
By Melvin Philips
© 2026 Created by Michael Levin.
Powered by