Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.scene.image.Image;
- import javafx.scene.image.PixelReader;
- import javafx.scene.image.WritableImage;
- import java.util.ArrayList;
- public class PuzzleImage {
- ArrayList<WritableImage> cutPieces = new ArrayList<>();
- ArrayList<Integer> rowInd = new ArrayList<>();
- ArrayList<Integer> colInd = new ArrayList<>();
- Image srcImg;
- boolean loaded = false;
- int rectNum;
- public void outprintRowsAndIndices(){
- System.out.println("Wiersze:");
- for(int i = 0; i < rowInd.size(); i++){
- System.out.println(rowInd.get(i));
- }
- System.out.println("Kolumny:");
- for(int i = 0; i < colInd.size(); i++){
- System.out.println(colInd.get(i));
- }
- }
- public void loadImage(String path){
- srcImg = new Image(path);
- loaded = true;
- }
- public void cutImage(int rectNum) throws Exception {
- this.rectNum = rectNum;
- System.out.println(rectNum);
- if(loaded) {
- double width, height;
- if (rectNum == 6) {
- height = srcImg.getHeight() / 2;
- System.out.println(height);
- width = srcImg.getWidth() / 3;
- System.out.println(width);
- PixelReader reader = srcImg.getPixelReader();
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < rectNum/2; j++) {
- cutPieces.add(new WritableImage(reader, (int) ((j+1) * width - width), (int) ((i+1) * height - height), (int) width, (int) height));
- rowInd.add(i);
- colInd.add(j);
- }
- }
- outprintRowsAndIndices();
- }
- if (rectNum == 8) {
- height = srcImg.getHeight() / 2;
- System.out.println(height);
- width = srcImg.getWidth() / 4;
- System.out.println(width);
- PixelReader reader = srcImg.getPixelReader();
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < rectNum / 2; j++) {
- cutPieces.add(new WritableImage(reader, (int) (j * width - width), (int) (i * height - height), (int) width, (int) height));
- rowInd.add(i - 1);
- colInd.add(j - 1);
- }
- }
- outprintRowsAndIndices();
- }
- if (rectNum == 10) {
- height = srcImg.getHeight() / 2;
- System.out.println(height);
- width = srcImg.getWidth() / 5;
- System.out.println(width);
- PixelReader reader = srcImg.getPixelReader();
- for (int i = 1; i <= 2; i++) {
- for (int j = 1; j <= rectNum / 2; j++) {
- cutPieces.add(new WritableImage(reader, (int) (j * width - width), (int) (i * height - height), (int) width, (int) height));
- rowInd.add(i - 1);
- colInd.add(j - 1);
- }
- }
- outprintRowsAndIndices();
- }
- }else{
- throw new Exception("Load an image first");
- }
- }
- public int row_getSize(){
- return rowInd.size();
- }
- public int col_getSize(){
- return colInd.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement