I am trying to take a screenshot and save it to di...
# compose-desktop
a
I am trying to take a screenshot and save it to disk of a composable component. a bit lost how to do this. as a starting point I tried taking a photo of the whole window with this code:
Copy code
fun takeScreenshot(frame: JFrame) {
    val screenshotImage = Robot().createScreenCapture(frame.bounds)
    frame.paint(screenshotImage.graphics)
    val file = File("screenShot.png")
    try {
        ImageIO.write(screenshotImage, "png", file)
    } catch (ex: IOException) {
        ex.printStackTrace()
    }
    Desktop.getDesktop().open(file)
}
passing
this@Window.window
(from a WindowScope). the saved screenshot has the right size but it only has the window's ribbon (with traffic lights on macos) without any of the windows content. anyone was able to take screenshots on compose desktop?
a
Does your app have the Mac OS X permissions for screen capturing?
Does it work if you capture the entire screen (with other apps on), for example?
l
If you just want a composable component, there's ImageComposeScene, which lets you set the content and get a Compose Image. This Image can then be saved to a file.
today i learned 1
a
Umm, I just noticed - why are you doing
Copy code
frame.paint(screenshotImage.graphics)
?
You should already have the screenshot in the image after
Copy code
val screenshotImage = Robot().createScreenCapture(frame.bounds)
a
appreciate the replies. didnt get the chance to try yet. will reply when i do