I want to use jAWTRobot ScreenCaptureToFile to take a screenshot of a specified area of the screen and save it to a file as a PNG file. Start and stop coordinates can be let's say imageview1.
A code snippet example how this works will do the trick, thanks.
Thanks, I am creating a notepad that looks very realistic and it's really nice (textarea with transparent background and a notepad image underneath), so I want to add a function to save a note to a file and another option to save it to clipboard memory, so that users will be able to post notes directly when using Facebook and for other uses.
I tried this your first example and will try your second code, but I only want to copy a portion of the screen, so the imageview1 is a good practice.
Waiting for debugger to connect...
Program started.
java.io.FileNotFoundException: E:\#PROGRAMMING\#Source Code\B4J\Notebook\Objects\d:\MyNote.png (Felaktig syntax för filnamn, katalognamn eller volymetikett)
at java.base/java.io.RandomAccessFile.open0(Native Method)
at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:343)
at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:259)
at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:214)
at java.desktop/javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:69)
at java.desktop/com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:55)
at java.desktop/javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:419)
at java.desktop/javax.imageio.ImageIO.write(ImageIO.java:1549)
at butt.droid.awtRobot.AWTRobot.ScreenCaptureToFile(AWTRobot.java:816)
at Notebook.Duologic.Se.main._btncapture_click(main.java:115)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
at java.base/java.lang.Thread.run(Thread.java:844)
As for my followup question, can your awesome library handle images to clipboard? I would like to have an option to store the image in clipboard so the note can be pasted directly to the screen, that would be awesome. Thanks for your help with this.
The comments for the ScreenCapture method say that the image will be saved relative to the current working directory. I think you will be better off using the ImageView1.Snapshot method.
The fx.Clipboard Object can place Images in the clipboard.