Hi all, is this the best approach to "center crop"...
# tornadofx
s
Hi all, is this the best approach to "center crop" an image into imageView??
Copy code
imageview(productViewModel.image) {
                    imageProperty().addListener { _, _, image ->
                        val newMeasure = image.width
                        val x = (image.width - newMeasure) / 2
                        val y = (image.height - newMeasure) / 2

                        val croppedPortion = Rectangle2D(x, y, newMeasure, newMeasure)
                        viewport = croppedPortion
                        fitWidth = 300.0
                        fitHeight = 300.0
                        isSmooth = true
                    }
                }
r
This assumes the image is square, and also will crop to the bottom right, not the center (unless I'm mistaken).
Did you mean
val newMeasure = image.width / 2
?