예제 #1
0
 /**
  * Returns the current component as buffered image. To save this buffered image as png you could
  * use for example: File file = new File("image.png"); ImageIO.write(Image, "png", file);
  *
  * @return the current component as buffered image
  */
 public BufferedImage getAsImage() {
   final BufferedImage IMAGE = UTIL.createImage(getWidth(), getHeight(), Transparency.TRANSLUCENT);
   final Graphics2D G2 = IMAGE.createGraphics();
   paintAll(G2);
   G2.dispose();
   return IMAGE;
 }
예제 #2
0
  private BufferedImage create_LCD_THRESHOLD_Image(
      final int WIDTH, final int HEIGHT, final Color COLOR) {
    if (WIDTH <= 0 || HEIGHT <= 0) {
      return null;
    }

    final BufferedImage IMAGE = UTIL.createImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();

    final GeneralPath LCD_THRESHOLD = new GeneralPath();
    LCD_THRESHOLD.setWindingRule(Path2D.WIND_EVEN_ODD);
    LCD_THRESHOLD.moveTo(IMAGE_WIDTH * 0.4444444444444444, IMAGE_HEIGHT * 0.7777777777777778);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.5555555555555556, IMAGE_HEIGHT * 0.7777777777777778);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.5555555555555556, IMAGE_HEIGHT * 0.8888888888888888);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.4444444444444444, IMAGE_HEIGHT * 0.8888888888888888);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.4444444444444444, IMAGE_HEIGHT * 0.7777777777777778);
    LCD_THRESHOLD.closePath();
    LCD_THRESHOLD.moveTo(IMAGE_WIDTH * 0.4444444444444444, IMAGE_HEIGHT * 0.3333333333333333);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.5555555555555556, IMAGE_HEIGHT * 0.3333333333333333);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.5555555555555556, IMAGE_HEIGHT * 0.7222222222222222);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.4444444444444444, IMAGE_HEIGHT * 0.7222222222222222);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.4444444444444444, IMAGE_HEIGHT * 0.3333333333333333);
    LCD_THRESHOLD.closePath();
    LCD_THRESHOLD.moveTo(0.0, IMAGE_HEIGHT);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH, IMAGE_HEIGHT);
    LCD_THRESHOLD.lineTo(IMAGE_WIDTH * 0.5, 0.0);
    LCD_THRESHOLD.lineTo(0.0, IMAGE_HEIGHT);
    LCD_THRESHOLD.closePath();
    G2.setColor(COLOR);
    G2.fill(LCD_THRESHOLD);

    G2.dispose();

    return IMAGE;
  }
예제 #3
0
  // <editor-fold defaultstate="collapsed" desc="Image related">
  private BufferedImage create_LCD_Image(final int WIDTH, final int HEIGHT) {
    if (WIDTH <= 0 || HEIGHT <= 0) {
      return null;
    }

    final BufferedImage IMAGE = UTIL.createImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();

    // Background rectangle
    final Point2D BACKGROUND_START = new Point2D.Double(0.0, 0.0);
    final Point2D BACKGROUND_STOP = new Point2D.Double(0.0, IMAGE_HEIGHT);
    if (BACKGROUND_START.equals(BACKGROUND_STOP)) {
      BACKGROUND_STOP.setLocation(0.0, BACKGROUND_START.getY() + 1);
    }

    final float[] BACKGROUND_FRACTIONS = {0.0f, 0.08f, 0.92f, 1.0f};

    final Color[] BACKGROUND_COLORS = {
      new Color(0.4f, 0.4f, 0.4f, 1.0f),
      new Color(0.5f, 0.5f, 0.5f, 1.0f),
      new Color(0.5f, 0.5f, 0.5f, 1.0f),
      new Color(0.9f, 0.9f, 0.9f, 1.0f)
    };

    final LinearGradientPaint BACKGROUND_GRADIENT =
        new LinearGradientPaint(
            BACKGROUND_START, BACKGROUND_STOP, BACKGROUND_FRACTIONS, BACKGROUND_COLORS);
    // final double BACKGROUND_CORNER_RADIUS = WIDTH * 0.09375;
    final double BACKGROUND_CORNER_RADIUS = WIDTH > HEIGHT ? (HEIGHT * 0.095) : (WIDTH * 0.095);
    final java.awt.geom.RoundRectangle2D BACKGROUND =
        new java.awt.geom.RoundRectangle2D.Double(
            0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, BACKGROUND_CORNER_RADIUS, BACKGROUND_CORNER_RADIUS);
    G2.setPaint(BACKGROUND_GRADIENT);
    G2.fill(BACKGROUND);

    // Foreground rectangle
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, IMAGE_HEIGHT - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
      FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {0.0f, 0.03f, 0.49f, 0.5f, 1.0f};

    final Color[] FOREGROUND_COLORS = {
      lcdColor.GRADIENT_START_COLOR,
      lcdColor.GRADIENT_FRACTION1_COLOR,
      lcdColor.GRADIENT_FRACTION2_COLOR,
      lcdColor.GRADIENT_FRACTION3_COLOR,
      lcdColor.GRADIENT_STOP_COLOR
    };

    if (lcdColor == LcdColor.CUSTOM) {
      G2.setPaint(customLcdBackground);
    } else {
      final LinearGradientPaint FOREGROUND_GRADIENT =
          new LinearGradientPaint(
              FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
      G2.setPaint(FOREGROUND_GRADIENT);
    }
    final double FOREGROUND_CORNER_RADIUS = BACKGROUND.getArcWidth() - 1;
    final java.awt.geom.RoundRectangle2D FOREGROUND =
        new java.awt.geom.RoundRectangle2D.Double(
            1,
            1,
            IMAGE_WIDTH - 2,
            IMAGE_HEIGHT - 2,
            FOREGROUND_CORNER_RADIUS,
            FOREGROUND_CORNER_RADIUS);
    G2.fill(FOREGROUND);

    G2.dispose();

    return IMAGE;
  }