JavaFX z Arią - powrót do strony głównej

JavaFX canvas: Atrybut obrazu ‘image smoothing’

Atrybut: image smoothing

Typ: boolean

Wartość domyślna: true.

Getter: boolean isImageSmoothing()

Setter: void setImageSmoothing(boolean)

Save/restore: true

Opis: Określa czy lepsze algorytmy wygładzanie obrazu w przypadku użycia metod drawImage są dostępne czy nie.

Atrybut obrazu ‘image smoothing’

Klasa Listing25_52a

Ściągnij klasę Listing25_52a

package rozdzial25c;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.text.Font;
import javafx.scene.text.FontSmoothingType;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

import java.io.File;
import java.io.FileInputStream;

public class Listing25_52a extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        try {
            Group root = new Group();
            Canvas cv = new Canvas(500, 300);
            GraphicsContext gc = cv.getGraphicsContext2D();
            //
            gc.setImageSmoothing(true);
            //-
            Image image = new Image(new FileInputStream(new 
                    File("rozdzial25c/src/rozdzial25c/rys25_19.png")));
            gc.drawImage(image, 10,10, image.getWidth()/2, 
                    image.getHeight()/2);
            //-
            boolean ist = gc.isImageSmoothing();
            System.out.println(ist);
            //-
            root.getChildren().add(cv);
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.setTitle("Atrybut obrazu 'image smoothing'");
            stage.setOnCloseRequest(e -> Platform.exit());
            stage.show();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
true
Atrybut obrazu 'image smoothing'
Rys. 25_58. Atrybut obrazu ‘image smoothing’
Klasa Listing25_52b

Ściągnij klasę Listing25_52b

package rozdzial25c;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.File;
import java.io.FileInputStream;

public class Listing25_52b extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        try {
            Group root = new Group();
            Canvas cv = new Canvas(500, 300);
            GraphicsContext gc = cv.getGraphicsContext2D();
            //
            gc.setImageSmoothing(false);
            //-
            Image image = new Image(new FileInputStream(new 
                    File("rozdzial25c/src/rozdzial25c/rys25_19.png")));
            gc.drawImage(image, 10,10, 
                    image.getWidth()/2, image.getHeight()/2);
            //-
            boolean ist = gc.isImageSmoothing();
            System.out.println(ist);
            //-
            root.getChildren().add(cv);
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.setTitle("Atrybut obrazu 'image smoothing'");
            stage.setOnCloseRequest(e -> Platform.exit());
            stage.show();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
false
Atrybut obrazu 'image smoothing'
Rys. 25_59. Atrybut obrazu ‘image smoothing’