0

Currently I want to display an image on an application. It is a 16x16 .png, however I do NOT want it smoothed. I would like it to keep its sharp squares and pixels, so I tried setting the smooth parameter via

public class MainMenu implements Initializable {

    @FXML ImageView imageViewOfImage;
    @FXML Label labelOfImageName;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        imageViewOfImage.setImage(new Image("images/grass_side.png", 100, 100, true, false));
        imageViewOfImage.setFitWidth(1024);
        imageViewOfImage.setFitHeight(1024);

        labelOfImageName.setText("grass_side.png");

    }
}

However, the image is still blurred. I tried moving the ImageView#setImage() below setting the size to see if that helped, however it still did nothing. I took a peek here, however I seem to be properly following the steps.

It looks much nicer when its around 300x300 pixels, but then it's smoothed out.

VeeAyeInIn
  • 193
  • 1
  • 12
  • Based on the linked question you should scale the image with the [Image constructor](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/Image.html#Image-java.lang.String-double-double-boolean-boolean-): `new Image("images/grass_side.png", 1024, 1024, true, false)` – Edwardth May 06 '18 at 15:07
  • I did that before this, and it resulted in the same thing. – VeeAyeInIn May 06 '18 at 15:08
  • I tested the example from [this answer](https://stackoverflow.com/a/16092631/4503858) and `new Image("images/grass_side.png", 1024, 1024, true, false)` doesn't smooth the pixels (with Java 8). But in your example you first load the Image with 100x100 (without smoothing the pixels) and then the ImageView scales the Image up to 1024x1024 and smooths the pixels. – Edwardth May 06 '18 at 15:24
  • Don't use `imageViewOfImage.setFitWidth` since this will always smooth the image when its scaled up. – Edwardth May 06 '18 at 15:25
  • This also works in FXML `` – Edwardth May 06 '18 at 15:50

0 Answers0