forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageLesson.java
More file actions
54 lines (47 loc) · 1.81 KB
/
ImageLesson.java
File metadata and controls
54 lines (47 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package fx;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* Created by max on 3/2/17.
*/
public class ImageLesson extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Image image = new Image(new FileInputStream("/home/max/IdeaProjects/JavaLessons/smile.jpg"));
ImageView imageView = new ImageView(image);
imageView.setFitHeight(300);
imageView.setFitWidth(400);
PixelReader pixelReader = image.getPixelReader();
for (int readY = 0; readY < image.getHeight(); readY++) {
for (int readX = 0; readX < image.getWidth(); readX++) {
Color color = pixelReader.getColor(readX, readY);
}
}
WritableImage wImage = new WritableImage((int)image.getWidth(),(int)image.getHeight());
PixelWriter pixelWriter = wImage.getPixelWriter();
for(int readY=0;readY<image.getHeight();readY++){
for(int readX=0; readX<image.getWidth();readX++){
pixelWriter.setColor(readX,readY,Color.ALICEBLUE);
}
}
ImageView wImageView = new ImageView(wImage);
wImageView.setFitHeight(300);
wImageView.setFitWidth(400);
ImageIO.write(SwingFXUtils.fromFXImage(wImage, null), "png", new FileOutputStream("test.png"));
Group root = new Group();
root.getChildren().addAll(imageView);
primaryStage.setScene(new Scene(root, 400, 300));
primaryStage.show();
}
}