Screenshots are always resized to 320x200 when saving.

This commit is contained in:
lantzelot-swe 2021-01-03 22:18:43 +01:00
parent 45c7f8b122
commit 36538f5732
2 changed files with 50 additions and 66 deletions

View File

@ -65,8 +65,8 @@ public class ScreenshotsPanel extends JPanel
private JButton edit2Button; private JButton edit2Button;
private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png")); private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/se/lantz/warning-icon.png"));
private String cropTooltip = private String editTooltip =
"<html>Optimal resolution for the carousel is 320x200.<br>Press to crop or scale the image to this size.</html>"; "<html>Optimal resolution for the carousel is 320x200.<br>Press to crop the image to this size (the border will be removed).<br>Otherwise it will be resized when saving which might make it blurry.</html>";
private boolean gamesFileUpdated = false; private boolean gamesFileUpdated = false;
FileNameExtensionFilter imagefilter = FileNameExtensionFilter imagefilter =
@ -578,27 +578,14 @@ public class ScreenshotsPanel extends JPanel
{ {
public void actionPerformed(ActionEvent arg0) public void actionPerformed(ActionEvent arg0)
{ {
JPopupMenu menu = new JPopupMenu(); BufferedImage croppedImage = FileManager.cropImageTo320x200(currentScreen1Image);
JMenuItem addItem = new JMenuItem("Crop to 320x200"); getScreen1ImageLabel().setIcon(new ImageIcon(croppedImage));
addItem.addActionListener(e -> { model.setScreen1Image(croppedImage);
model.setScreen1Image(cropImage(currentScreen1Image, getScreen1ImageLabel())); edit1Button.setVisible(false);
edit1Button.setVisible(false);
});
menu.add(addItem);
JMenuItem editItem = new JMenuItem("Scale to 320x200");
editItem.addActionListener(e -> {
BufferedImage scaledImage = scaleImage(currentScreen1Image);
model.setScreen1Image(scaledImage);
edit1Button.setVisible(false);
});
menu.add(editItem);
menu.show(edit1Button, 15, 15);
} }
}); });
edit1Button.setMargin(new Insets(1, 3, 1, 3)); edit1Button.setMargin(new Insets(1, 3, 1, 3));
edit1Button.setToolTipText(cropTooltip); edit1Button.setToolTipText(editTooltip);
edit1Button.setVisible(false); edit1Button.setVisible(false);
} }
return edit1Button; return edit1Button;
@ -613,26 +600,14 @@ public class ScreenshotsPanel extends JPanel
{ {
public void actionPerformed(ActionEvent arg0) public void actionPerformed(ActionEvent arg0)
{ {
JPopupMenu menu = new JPopupMenu(); BufferedImage croppedImage = FileManager.cropImageTo320x200(currentScreen2Image);
JMenuItem addItem = new JMenuItem("Crop to 320x200"); getScreen2ImageLabel().setIcon(new ImageIcon(croppedImage));
addItem.addActionListener(e -> { model.setScreen2Image(croppedImage);
model.setScreen2Image(cropImage(currentScreen2Image, getScreen2ImageLabel())); edit2Button.setVisible(false);
edit2Button.setVisible(false);
});
menu.add(addItem);
JMenuItem editItem = new JMenuItem("Scale to 320x200");
editItem.addActionListener(e -> {
BufferedImage scaledImage = scaleImage(currentScreen2Image);
model.setScreen2Image(scaledImage);
edit2Button.setVisible(false);
});
menu.add(editItem);
menu.show(edit2Button, 15, 15);
} }
}); });
edit2Button.setMargin(new Insets(1, 3, 1, 3)); edit2Button.setMargin(new Insets(1, 3, 1, 3));
edit2Button.setToolTipText(cropTooltip); edit2Button.setToolTipText(editTooltip);
edit2Button.setVisible(false); edit2Button.setVisible(false);
} }
return edit2Button; return edit2Button;
@ -692,30 +667,6 @@ public class ScreenshotsPanel extends JPanel
} }
} }
private BufferedImage cropImage(BufferedImage originalImage, JLabel screenLabel)
{
// Crop to right size for C64: Remove the border to fit nicely in the carousel.
BufferedImage newImage = originalImage
.getSubimage((originalImage.getWidth() - 320) / 2, ((originalImage.getHeight() - 200) / 2) - 1, 320, 200);
BufferedImage copyOfImage =
new BufferedImage(newImage.getWidth(), newImage.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
screenLabel.setIcon(new ImageIcon(newImage));
return newImage;
}
private BufferedImage scaleImage(BufferedImage originalImage)
{
// Scale to right size.
Image newImage = originalImage.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
BufferedImage copyOfImage =
new BufferedImage(newImage.getWidth(null), newImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
return copyOfImage;
}
private void selectGameFile() private void selectGameFile()
{ {
final JFileChooser fileChooser = new JFileChooser(); final JFileChooser fileChooser = new JFileChooser();

View File

@ -31,7 +31,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import se.lantz.db.DbConnector; import se.lantz.db.DbConnector;
import se.lantz.gui.MainWindow;
import se.lantz.model.InfoModel; import se.lantz.model.InfoModel;
import se.lantz.model.MainViewModel; import se.lantz.model.MainViewModel;
import se.lantz.model.SystemModel; import se.lantz.model.SystemModel;
@ -108,6 +107,8 @@ public class FileManager
try try
{ {
File outputfile = new File(SCREENS + screen1FileName); File outputfile = new File(SCREENS + screen1FileName);
//Scale if not the right size
screen1 = scaleImageTo320x200(screen1);
ImageIO.write(screen1, "png", outputfile); ImageIO.write(screen1, "png", outputfile);
} }
catch (IOException e) catch (IOException e)
@ -121,6 +122,8 @@ public class FileManager
try try
{ {
File outputfile = new File(SCREENS + screen2FileName); File outputfile = new File(SCREENS + screen2FileName);
//Scale if not the right size
screen2 = scaleImageTo320x200(screen2);
ImageIO.write(screen2, "png", outputfile); ImageIO.write(screen2, "png", outputfile);
} }
catch (IOException e) catch (IOException e)
@ -749,14 +752,44 @@ public class FileManager
{ {
try try
{ {
Files.walk(TEMP_PATH) if (Files.exists(TEMP_PATH))
.sorted(Comparator.reverseOrder()) {
.map(Path::toFile) Files.walk(TEMP_PATH)
.forEach(File::delete); .sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
} }
catch (IOException e) catch (IOException e)
{ {
ExceptionHandler.handleException(e, "Could not delete temp folder"); ExceptionHandler.handleException(e, "Could not delete temp folder");
} }
} }
public static BufferedImage scaleImageTo320x200(BufferedImage originalImage)
{
if (originalImage.getWidth() != 320 || originalImage.getHeight() != 200)
{
// Scale to right size.
Image newImage = originalImage.getScaledInstance(320, 200, Image.SCALE_DEFAULT);
BufferedImage copyOfImage =
new BufferedImage(newImage.getWidth(null), newImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
return copyOfImage;
}
return originalImage;
}
public static BufferedImage cropImageTo320x200(BufferedImage originalImage)
{
// Crop to right size for C64: Remove the border to fit nicely in the carousel.
BufferedImage newImage = originalImage
.getSubimage((originalImage.getWidth() - 320) / 2, ((originalImage.getHeight() - 200) / 2) - 1, 320, 200);
BufferedImage copyOfImage =
new BufferedImage(newImage.getWidth(), newImage.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = copyOfImage.createGraphics();
g.drawImage(newImage, 0, 0, null);
return newImage;
}
} }