Плитки для BufferedImage в Java, любое разрешение - PullRequest
0 голосов
/ 15 ноября 2018

У меня есть класс для разделения и объединения изображений в тайлы.Он отлично работает, когда стороны плитки соответствуют размерам изображения, то есть высота 250, высота плитки 25. Но когда это не так, он не создает меньшие плитки на границах, как должно.

Гдебыло бы проблемой, чтобы правильно создать плитки границы меньше остальных?

public void joinTiles(){

    int rows = getRow();
    int columns = getCol();
    int smallWidth = getTilew();
    int smallHeight = getTileh();

    BufferedImage comb = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D) comb.getGraphics();

    g.setColor(Color.RED);

    for (int row = 0; row < rows; row++){
        for (int col = 0; col < columns; col++){

            BufferedImage piece = getMatImg()[row][col];

            if (col == columns - 1) smallWidth = getWidth() - (getTilew() * col);           
            if (row == rows - 1) smallHeight = getHeight() - (getTileh() * row);

            g.drawImage(piece, col * smallWidth, row * smallHeight, smallWidth, smallHeight, null);
            g.drawRect(col * smallWidth, row * smallHeight, smallWidth, smallHeight);

        }
        smallWidth = getTilew();
        smallHeight = getTileh();
    }
    g.dispose();

    setSourceImg(comb); 
}

Исходное изображение 512 * 512

Image with whole tiles(256*128)

Image with another tile size (256*100)

...