AWT is forbidden on 1.13+ (this includes BufferedImage)
Instead use NativeImage on 1.13+ via newly introduced Image class. See Image docs for details. Also fixes an issue with thumbnail taking on 1.13+: The original ScreenshotHelper method is now async, luckily there's a sync variant and as a bonus it directly returns a NativeImage so we can skip having to read the screenshot from disk.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.replaymod.extras.advancedscreenshots;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.SettingsRegistry;
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import com.replaymod.extras.Setting;
|
||||
import com.replaymod.render.RenderSettings;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
@@ -14,8 +15,6 @@ import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
public class GuiUploadScreenshot extends AbstractGuiPopup<GuiUploadScreenshot> {
|
||||
@@ -68,22 +67,10 @@ public class GuiUploadScreenshot extends AbstractGuiPopup<GuiUploadScreenshot> {
|
||||
}
|
||||
|
||||
if (veer) {
|
||||
veerUploadButton.onClick(() -> {
|
||||
try {
|
||||
Desktop.getDesktop().browse(URI.create("https://veer.tv/upload"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
veerUploadButton.onClick(() -> MCVer.openURL(URI.create("https://veer.tv/upload")));
|
||||
}
|
||||
|
||||
showOnDiskButton.onClick(() -> {
|
||||
try {
|
||||
Desktop.getDesktop().browse(renderSettings.getOutputFile().toURI());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
showOnDiskButton.onClick(() -> MCVer.openFile(renderSettings.getOutputFile().getParentFile()));
|
||||
|
||||
closeButton.onClick(() -> {
|
||||
if (neverOpenCheckbox.isChecked()) {
|
||||
|
||||
@@ -8,10 +8,9 @@ import com.replaymod.render.frame.RGBFrame;
|
||||
import com.replaymod.render.rendering.FrameConsumer;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import de.johni0702.minecraft.gui.versions.Image;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -28,23 +27,20 @@ public class ScreenshotWriter implements FrameConsumer<RGBFrame> {
|
||||
// skip the first frame, in which not all chunks are properly loaded
|
||||
if (frame.getFrameId() == 0) return;
|
||||
|
||||
try {
|
||||
final ReadableDimension frameSize = frame.getSize();
|
||||
|
||||
BufferedImage img = new BufferedImage(frameSize.getWidth(), frameSize.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
final ReadableDimension frameSize = frame.getSize();
|
||||
try (Image img = new Image(frameSize.getWidth(), frameSize.getHeight())) {
|
||||
for (int y = 0; y < frameSize.getHeight(); y++) {
|
||||
for (int x = 0; x < frameSize.getWidth(); x++) {
|
||||
byte r = frame.getByteBuffer().get();
|
||||
byte g = frame.getByteBuffer().get();
|
||||
byte b = frame.getByteBuffer().get();
|
||||
|
||||
int color = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
|
||||
img.setRGB(x, y, color);
|
||||
img.setRGBA(x, y, r, g, b, 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
outputFile.getParentFile().mkdirs();
|
||||
ImageIO.write(img, "PNG", outputFile);
|
||||
img.writePNG(outputFile);
|
||||
} catch (OutOfMemoryError e) {
|
||||
e.printStackTrace();
|
||||
CrashReport report = CrashReport.create(e, "Exporting frame");
|
||||
|
||||
Reference in New Issue
Block a user