Пример #1
0
  private BufferedImage generateFrame(GifFrame frame) {
    int width = frame.getColumns() * CELL_WIDTH;
    BufferedImage img =
        new BufferedImage(width, frame.getRows() * CELL_HEIGHT + TEXT_AREA_HEIGHT, IMAGE_TYPE_GIF);
    Graphics graphics = img.getGraphics();
    for (int row = 0; row < frame.getRows(); row++) {
      for (int col = 0; col < frame.getColumns(); col++) {
        ImageIcon icon =
            new ImageIcon(
                "site/images/" + frame.getBoard().get(row, col).getImageFilename() + ".png");
        graphics.drawImage(icon.getImage(), col * CELL_WIDTH, row * CELL_HEIGHT, null);
      }
    }

    for (BoxOverlay overlay : frame.getOverlays()) {
      graphics.setColor(overlay.getColor());
      Rectangle rect = overlay.getRectangle();
      int rect_x = rect.getLeft() * CELL_WIDTH - OVERLAY_PADDING;
      int rect_y = rect.getTop() * CELL_HEIGHT - OVERLAY_PADDING;
      int rect_width = (rect.getRight() - rect.getLeft() + 1) * CELL_WIDTH + 2 * OVERLAY_PADDING;
      int rect_height = (rect.getBottom() - rect.getTop() + 1) * CELL_HEIGHT + 2 * OVERLAY_PADDING;
      graphics.drawRect(rect_x, rect_y, rect_width, rect_height);
      graphics.drawRect(rect_x - 1, rect_y - 1, rect_width + 2, rect_height + 2);
    }

    graphics.setColor(FONT_COLOR);
    graphics.setFont(FONT);
    FontMetrics fm = graphics.getFontMetrics();
    graphics.drawString(
        frame.getText(),
        width / 2 - fm.stringWidth(frame.getText()) / 2,
        frame.getRows() * CELL_HEIGHT + TEXT_AREA_HEIGHT / 2 + fm.getHeight() / 2);

    return img;
  }