package delta;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.shape.*;
import static javafx.application.Application.launch;
import javafx.scene.paint.Color;
import javafx.scene.input.MouseEvent;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.PixelReader;
import javafx.scene.canvas.GraphicsContext;
public class pro extends Application {
Canvas cam;
GraphicsContext gc;
int[][] mr=new int[2000][2000];
int[][] mg=new int[2000][2000];
int[][] mb=new int[2000][2000];
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Image im = new Image("file:neko.jpg");
int h=(int)im.getHeight();
int w=(int)im.getWidth();
ImageView imageView = new ImageView();
imageView.setImage(im);
PixelReader reader = im.getPixelReader();
int mx,nx;
for(mx=0;mx<h;mx++){
for(nx=0;nx<w;nx++){
Color col = reader.getColor(nx, mx);
mr[mx][nx] =(int)(255*col.getRed());
mg[mx][nx] = (int)(255*col.getGreen());
mb[mx][nx] = (int)(255*col.getBlue());
}
}
cam = new Canvas(h,w);
gc = cam.getGraphicsContext2D();
for(mx=0;mx<500;mx++){
for(nx=0;nx<500;nx++){
Color c = Color.rgb(mr[mx][nx],mg[mx][nx],mb[mx][nx]);
gc.setFill(c);
gc.fillRect(nx,mx,1,1);
}
}
cam.addEventHandler(MouseEvent.MOUSE_CLICKED,
new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
int x1,y1;
int px=(int)e.getX();
int py=(int)e.getY();
gc.setFill(Color.RED);
gc.fillRect(px,py,10,10);
}
});
Group root = new Group();
Scene scene = new Scene(root, 700, 700);
root.getChildren().add(cam);
primaryStage.setTitle("グラフ");
primaryStage.setScene(scene);
primaryStage.show();
}
}
最終更新:2015年06月13日 09:21