Update TheImaniPulator.java

This commit is contained in:
aaditagrawal 2024-10-26 00:38:45 +05:30 committed by GitHub
parent 49a54cf5eb
commit 235220f3e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -206,11 +206,13 @@ public class TheImaniPulator extends Application {
Label saveLabel = new Label("Save Options"); Label saveLabel = new Label("Save Options");
Label specialLabel = new Label("Special Effects"); Label specialLabel = new Label("Special Effects");
Label musicLabel = new Label("Music Controls"); Label musicLabel = new Label("Music Controls");
Label resetLabel = new Label("Reset Options");
filterLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;"); filterLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;");
saveLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;"); saveLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;");
specialLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;"); specialLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;");
musicLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;"); musicLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;");
resetLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16px;");
Button blurButton = new Button("Blur"); Button blurButton = new Button("Blur");
Button grayscaleButton = new Button("Grayscale"); Button grayscaleButton = new Button("Grayscale");
@ -224,12 +226,22 @@ public class TheImaniPulator extends Application {
Button pauseMusicButton = new Button("Pause Music"); Button pauseMusicButton = new Button("Pause Music");
Button vignetteButton = new Button("Vignette"); Button vignetteButton = new Button("Vignette");
// Style reset button differently
resetButton.setStyle(
"-fx-background-color: black;" +
"-fx-text-fill: white;" +
"-fx-font-family: 'SF Pro Text';" +
"-fx-font-size: 16px;" +
"-fx-padding: 12px 20px;" +
"-fx-background-radius: 10px;" +
"-fx-cursor: hand;"
);
int buttonWidth = 150; int buttonWidth = 150;
for (Button btn : new Button[] { for (Button btn : new Button[] {
blurButton, blurButton,
grayscaleButton, grayscaleButton,
sepiaButton, sepiaButton,
resetButton,
saveAsJpegButton, saveAsJpegButton,
saveAsPngButton, saveAsPngButton,
saveAsHeifButton, saveAsHeifButton,
@ -249,9 +261,13 @@ public class TheImaniPulator extends Application {
filterGrid.add(blurButton, 0, 0); filterGrid.add(blurButton, 0, 0);
filterGrid.add(grayscaleButton, 1, 0); filterGrid.add(grayscaleButton, 1, 0);
filterGrid.add(sepiaButton, 0, 1); filterGrid.add(sepiaButton, 0, 1);
filterGrid.add(resetButton, 1, 1);
filterGrid.add(vignetteButton, 0, 2); filterGrid.add(vignetteButton, 0, 2);
GridPane resetGrid = new GridPane();
resetGrid.setHgap(10);
resetGrid.setVgap(10);
resetGrid.add(resetButton, 0, 0);
GridPane saveGrid = new GridPane(); GridPane saveGrid = new GridPane();
saveGrid.setHgap(10); saveGrid.setHgap(10);
saveGrid.setVgap(10); saveGrid.setVgap(10);
@ -318,7 +334,7 @@ public class TheImaniPulator extends Application {
}); });
saveAsJpegButton.setOnAction(e -> { saveAsJpegButton.setOnAction(e -> {
saveImage(primaryStage, "jpeg"); saveImage(primaryStage, "jpg"); // Changed from jpeg to jpg
updateStatus("Saving as JPEG"); updateStatus("Saving as JPEG");
}); });
@ -389,6 +405,8 @@ public class TheImaniPulator extends Application {
titleLabel, titleLabel,
filterLabel, filterLabel,
filterGrid, filterGrid,
resetLabel,
resetGrid,
saveLabel, saveLabel,
saveGrid, saveGrid,
specialLabel, specialLabel,
@ -444,10 +462,29 @@ public class TheImaniPulator extends Application {
File file = fileChooser.showSaveDialog(stage); File file = fileChooser.showSaveDialog(stage);
if (file != null) { if (file != null) {
try { try {
BufferedImage bufferedImage = SwingFXUtils.fromFXImage( // Get the original image directly instead of taking a snapshot
imageView.getImage(), Image image = imageView.getImage();
null int width = (int) image.getWidth();
int height = (int) image.getHeight();
BufferedImage bufferedImage = new BufferedImage(
width,
height,
BufferedImage.TYPE_INT_RGB
); );
PixelReader reader = image.getPixelReader();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
Color color = reader.getColor(x, y);
int rgb =
((int) (color.getRed() * 255) << 16) |
((int) (color.getGreen() * 255) << 8) |
((int) (color.getBlue() * 255));
bufferedImage.setRGB(x, y, rgb);
}
}
ImageIO.write(bufferedImage, format, file); ImageIO.write(bufferedImage, format, file);
} catch (IOException ex) { } catch (IOException ex) {
Alert alert = new Alert(AlertType.ERROR); Alert alert = new Alert(AlertType.ERROR);