Sebastian Kürten
05/16/2022, 8:41 PMSebastian Kürten
05/16/2022, 8:46 PMKirill Grouchnikov
05/16/2022, 8:51 PMImageComposeScene
is your friendKirill Grouchnikov
05/16/2022, 8:52 PMrender()
+ encodeToData().bytes
+ File.writeBytes()
Sebastian Kürten
05/16/2022, 9:27 PMSebastian Kürten
05/18/2022, 11:05 AMWindow
with ImageComposeScene
and was able to render and store to file the way you suggested.
I'm still curious whether it's possible or planned to use the testing API similar to the way its possible with Android. I found Maven artifact org.jetbrains.compose.ui:ui-test-junit4:1.1.1
and was able to change most imports on the Android example in the blog post above so that they resolve.
What does not seem to be available is captureToImage()
, I'm assuming it's going to be added eventually:
onRoot()
.captureToImage()
.asAndroidBitmap()
.save(file)
Why I'm interested in this: the testing API also has support for simulating clicks on UI elements, so I guess it will help making series of screenshots from various parts of the UI without needing to manipulate state internally, but can be manipulated by simulated mouse and key events.Sebastian Kürten
05/18/2022, 11:07 AMBufferedImage image = new BufferedImage(
component.getWidth(),
component.getHeight(),
BufferedImage.TYPE_INT_RGB
);
// call the Component's paint method, using
// the Graphics object of the image.
component.paint( image.getGraphics() );
Sebastian Kürten
05/18/2022, 11:09 AMpaint()
on the graphics obtained from a buffered image. Kind of cool and wondering if there's potentially a way to trick compose into rendering into an offscreen buffer, too. That would allow to capture screenshots of an app in production (say with some magic keyboard shortcut) without using external screenshot tools.