Jump to content

Forge ScreenShotEvent does not work well


nashiroaoi

Recommended Posts

Hello, I'm making a mod with forge 1.16.3.

I want to get screenshot path and read it and change to base64-string.

 

@SubscribeEvent
public void onScreenShot(ScreenshotEvent event) throws IOException {
    byte[] data = Files.readAllBytes(event.getScreenshotFile().toPath());
    String base64str = Base64.getEncoder().encodeToString(data);
    LOGGER.info(base64str);
}

But it throw java.nio.file.NoSuchFileException: [Screenshotfile.png]

and crashed.

ScreenShotEvent fired normally so I think that screen shot file is not created yet when event fires but I don't know how should I fix.

Could you help me, please?

 

Link to comment
Share on other sites

3 hours ago, nashiroaoi said:

ScreenShotEvent fired normally so I think that screen shot file is not created yet when event fires but I don't know how should I fix.

The NativeImage is written to the file location after the event is called. You can specify the new location for the file if you would like. However, you want to read any information directly from the NativeImage instead of where it will be posted.

Link to comment
Share on other sites

16 hours ago, ChampionAsh5357 said:

The NativeImage is written to the file location after the event is called. You can specify the new location for the file if you would like. However, you want to read any information directly from the NativeImage instead of where it will be posted.

I changed

byte[] data = Files.readAllBytes(event.getScreenshotFile().toPath());

to

byte[] data = event.getImage().getBytes();

on my code then it completely worked!

Thank you so much!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.