Пример #1
0
 private static BufferedImage makeBufferedImage(Icon icon, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = image.createGraphics();
   icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconWidth()) / 2);
   g.dispose();
   return image;
 }
  @Override
  protected void paintBackground(Graphics g, JComponent component) {
    getGlassParameters();
    Graphics2D g2d = (Graphics2D) g.create();

    if (getOrientation().isHorizontal()) {
      paintBackground(
          g2d,
          0,
          0,
          component.getWidth(),
          component.getHeight(),
          getOrientation().isHorizontal(),
          component);
    } else {
      paintBackground(
          g2d,
          0,
          0,
          component.getHeight(),
          component.getWidth(),
          getOrientation().isHorizontal(),
          component);
    }

    g2d.dispose();
  }
Пример #3
0
  public BufferedImage createCrystalCase(Image cover) {
    BufferedImage crystal =
        new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = crystal.createGraphics();
    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    int width = cover.getWidth(null);
    int height = cover.getHeight(null);

    float scale;

    if (width > height) {
      scale = (float) IMAGE_WIDTH / (float) width;
    } else {
      scale = (float) IMAGE_HEIGHT / (float) height;
    }

    int scaledWidth = (int) ((float) width * scale);
    int scaledHeight = (int) ((float) height * scale);

    int x = (IMAGE_WIDTH - scaledWidth) / 2;
    int y = (IMAGE_HEIGHT - scaledHeight) / 2;

    g2.drawImage(cover, x, y, scaledWidth, scaledHeight, null);

    g2.dispose();

    return crystal;
  }
Пример #4
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Пример #5
0
 public Image getImage() {
   BufferedImage image =
       new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = image.createGraphics();
   paintIcon(null, g, 0, 0);
   g.dispose();
   return image;
 }
Пример #6
0
  private void applyAlphaMask(
      BufferedImage buffer, BufferedImage alphaMask, int itemWidth, int itemHeight) {

    Graphics2D g2 = buffer.createGraphics();
    g2.setComposite(AlphaComposite.DstOut);
    g2.drawImage(alphaMask, null, 0, itemHeight);
    g2.dispose();
  }
Пример #7
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.translate(x, y);
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setPaint(Color.ORANGE);
   g2.fill(star);
   g2.dispose();
 }
  /** Draws this handle. */
  public void draw(Graphics2D g) {
    Graphics2D gg = (Graphics2D) g.create();
    gg.transform(view.getDrawingToViewTransform());
    for (Connector c : connectors) {
      c.draw(gg);
    }

    gg.dispose();
    drawCircle(g, (getTarget() == null) ? Color.red : Color.green, Color.black);
  }
Пример #9
0
 public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w, h);
   g2.drawImage(bi, -x, -y, null); // this);
   g2.dispose();
   return image;
 }
Пример #10
0
 public static BufferedImage scaleImage(BufferedImage bi, double scale) {
   int w1 = (int) (Math.round(scale * bi.getWidth()));
   int h1 = (int) (Math.round(scale * bi.getHeight()));
   BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w1, h1);
   g2.drawImage(bi, 0, 0, w1, h1, null); // this);
   g2.dispose();
   return image;
 }
Пример #11
0
 public void paint(Graphics2D g2d) {
   Point p = getLocation();
   if (p != null) {
     g2d = (Graphics2D) g2d.create();
     g2d.setColor(Color.BLUE);
     Shape shape = getShape();
     int x = (int) p.x - (shape.getBounds().width / 2);
     int y = (int) p.y - (shape.getBounds().height / 2);
     g2d.translate(x, y);
     g2d.fill(shape);
     g2d.dispose();
   }
 }
Пример #12
0
  /*
   * (non-Javadoc)
   *
   * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
   * int, int)
   */
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.translate(x, y);

    double coef1 = (double) this.width / (double) getOrigWidth();
    double coef2 = (double) this.height / (double) getOrigHeight();
    double coef = Math.min(coef1, coef2);
    g2d.scale(coef, coef);
    paint(g2d);
    g2d.dispose();
  }
Пример #13
0
 public static BufferedImage rotateImage(BufferedImage bi) {
   int w = bi.getWidth();
   int h = bi.getHeight();
   BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white); // getBackground());
   g2.fillRect(0, 0, h, w);
   g2.rotate(90 * Math.PI / 180);
   g2.drawImage(bi, 0, -h, w, h, null); // this);
   g2.dispose();
   return image;
 }
Пример #14
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    if (image == null) {
      image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB);
      double coef = Math.min((double) width / (double) 68, (double) height / (double) 81);

      Graphics2D g2d = image.createGraphics();
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.scale(coef, coef);
      paint(g2d);
      g2d.dispose();
    }

    g.drawImage(image, x, y, null);
  }
Пример #15
0
  private Shape generateShapeFromText() {
    Font font = new Font(fontFamily, Font.PLAIN, fontSize);
    BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = img.createGraphics();

    try {
      GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), str);
      float dispX = x;
      float dispY = (float) (y - vect.getVisualBounds().getY());
      Shape shape = vect.getOutline(dispX, dispY);

      return shape;
    } finally {
      g2.dispose();
    }
  }
Пример #16
0
  /*
   * (non-Javadoc)
   *
   * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
   * int, int)
   */
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.translate(x, y);

    Area clip = new Area(new Rectangle(0, 0, this.width, this.height));
    if (g2d.getClip() != null) clip.intersect(new Area(g2d.getClip()));
    g2d.setClip(clip);

    double coef1 = (double) this.width / (double) getOrigWidth();
    double coef2 = (double) this.height / (double) getOrigHeight();
    double coef = Math.min(coef1, coef2);
    g2d.scale(coef, coef);
    paint(g2d);
    g2d.dispose();
  }
Пример #17
0
  private BufferedImage createReflection(BufferedImage item, int itemWidth, int itemHeight) {

    BufferedImage buffer =
        new BufferedImage(itemWidth, itemHeight << 1, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = buffer.createGraphics();

    g.drawImage(item, null, null);
    g.translate(0, itemHeight << 1);

    AffineTransform reflectTransform = AffineTransform.getScaleInstance(1.0, -1.0);
    g.drawImage(item, reflectTransform, null);
    g.translate(0, -(itemHeight << 1));

    g.dispose();

    return buffer;
  }
Пример #18
0
  public BufferedImage createGradientMask(int itemWidth, int itemHeight) {
    BufferedImage gradient = new BufferedImage(itemWidth, itemHeight, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = gradient.createGraphics();
    GradientPaint painter =
        new GradientPaint(
            0.0f,
            0.0f,
            new Color(1.0f, 1.0f, 1.0f, 0.5f),
            0.0f,
            itemHeight / 2.0f,
            new Color(1.0f, 1.0f, 1.0f, 1.0f));
    g.setPaint(painter);
    g.fill(new Rectangle2D.Double(0, 0, itemWidth, itemHeight));

    g.dispose();

    return gradient;
  }
Пример #19
0
  @Override
  public void draw(Graphics2D g) {
    double opacity = get(OPACITY);
    opacity = Math.min(Math.max(0d, opacity), 1d);
    if (opacity != 0d) {
      if (opacity != 1d) {
        Rectangle2D.Double drawingArea = getDrawingArea();

        Rectangle2D clipBounds = g.getClipBounds();
        if (clipBounds != null) {
          Rectangle2D.intersect(drawingArea, clipBounds, drawingArea);
        }

        if (!drawingArea.isEmpty()) {

          BufferedImage buf =
              new BufferedImage(
                  (int) ((2 + drawingArea.width) * g.getTransform().getScaleX()),
                  (int) ((2 + drawingArea.height) * g.getTransform().getScaleY()),
                  BufferedImage.TYPE_INT_ARGB);
          Graphics2D gr = buf.createGraphics();
          gr.scale(g.getTransform().getScaleX(), g.getTransform().getScaleY());
          gr.translate((int) -drawingArea.x, (int) -drawingArea.y);
          gr.setRenderingHints(g.getRenderingHints());
          drawFigure(gr);
          gr.dispose();
          Composite savedComposite = g.getComposite();
          g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) opacity));
          g.drawImage(
              buf,
              (int) drawingArea.x,
              (int) drawingArea.y,
              2 + (int) drawingArea.width,
              2 + (int) drawingArea.height,
              null);
          g.setComposite(savedComposite);
        }
      } else {
        drawFigure(g);
      }
    }
  }
Пример #20
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int w = src.getWidth();
    int h = src.getHeight();

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(width, height),
              dstCM.isAlphaPremultiplied(),
              null);
    }

    Graphics2D g = dst.createGraphics();
    g.drawRenderedImage(src, AffineTransform.getTranslateInstance(-x, -y));
    g.dispose();

    return dst;
  }
Пример #21
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(getBackground());
   g.fillRect(0, 0, getWidth(), getHeight());
   int w = bufferedImage.getWidth(this);
   int h = bufferedImage.getHeight(this);
   if (mode == Flip.NONE) {
     g.drawImage(bufferedImage, 0, 0, w, h, this);
   } else if (mode == Flip.VERTICAL) {
     AffineTransform at = AffineTransform.getScaleInstance(1d, -1d);
     at.translate(0, -h);
     Graphics2D g2 = (Graphics2D) g.create();
     g2.drawImage(bufferedImage, at, this);
     g2.dispose();
   } else if (mode == Flip.HORIZONTAL) {
     AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
     at.translate(-w, 0);
     AffineTransformOp atOp = new AffineTransformOp(at, null);
     g.drawImage(atOp.filter(bufferedImage, null), 0, 0, w, h, this);
   }
 }
Пример #22
0
  private static int[] makeGradientPallet() {
    BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    Point2D start = new Point2D.Float(0f, 0f);
    Point2D end = new Point2D.Float(99f, 0f);
    float[] dist = {0f, .5f, 1f};
    Color[] colors = {Color.RED, Color.YELLOW, Color.GREEN};
    g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
    g2.fillRect(0, 0, 100, 1);
    g2.dispose();

    int width = image.getWidth(null);
    int[] pallet = new int[width];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
    try {
      pg.grabPixels();
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
    return pallet;
  }
Пример #23
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();

    if (dst == null)
      dst =
          new BufferedImage(
              width + leftBorder + rightBorder, height + topBorder + bottomBorder, src.getType());
    Graphics2D g = dst.createGraphics();
    if (borderPaint != null) {
      g.setPaint(borderPaint);
      if (leftBorder > 0) g.fillRect(0, 0, leftBorder, height);
      if (rightBorder > 0) g.fillRect(width - rightBorder, 0, rightBorder, height);
      if (topBorder > 0) g.fillRect(leftBorder, 0, width - leftBorder - rightBorder, topBorder);
      if (bottomBorder > 0)
        g.fillRect(
            leftBorder, height - bottomBorder, width - leftBorder - rightBorder, bottomBorder);
    }
    g.drawRenderedImage(src, AffineTransform.getTranslateInstance(leftBorder, rightBorder));
    g.dispose();
    return dst;
  }
Пример #24
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.translate(x, y);

    g2.setStroke(new BasicStroke(BORDER_WIDTH));
    g2.setPaint(LINE_COLOR);
    g2.draw(BORDER);

    g2.setStroke(new BasicStroke(SLIT_WIDTH));
    g2.setColor(UIManager.getColor("Panel.background"));

    int n = SLIT_NUM + 1;
    int v = ICON_SIZE / n;
    int m = n * v;
    for (int i = 1; i < n; i++) {
      int a = i * v;
      g2.drawLine(a, 0, a, m);
      g2.drawLine(0, a, m, a);
    }

    // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v);
    // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v);
    // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v);
    // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v);
    // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v);
    // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v);

    g2.setPaint(LINE_COLOR);
    Rectangle2D b = ARROW.getBounds();
    Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d);
    AffineTransform toCenterAT =
        AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY());
    g2.fill(toCenterAT.createTransformedShape(ARROW));
    g2.dispose();
  }
    public void paint(Graphics g) {
      float ffc, flw;
      int cw, ch;
      Graphics2D g2 = (Graphics2D) g;
      Dmax = canvas.getSize();

      cw = Dmax.width;
      ch = Dmax.height;

      if (bimw != cw || bimh != ch) {

        if (bimw != cw || bimh != ch) {
          bim = (BufferedImage) createImage(cw, ch);
        }

        Graphics2D bimg2 = bim.createGraphics();

        bimg2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        bimg2.setBackground(DatanGraphics.ct[0]);
        bimg2.clearRect(0, 0, cw, ch);

        DminInner.width = Dmin.width + 1;
        DminInner.height = Dmin.height + 1;
        DmaxInner.width = Dmax.width - 2;
        DmaxInner.height = Dmax.height - 2;

        bimg2.setTransform(affTransf(DminInner, DmaxInner, dmin, dmax));
        drawPolylines(bimg2);
        bimw = cw;
        bimh = ch;
        bimg2.dispose();
        bimg2 = null;
      }

      g2.drawImage(bim, 0, 0, this);
    }
Пример #26
0
  public void run() {
    Thread me = Thread.currentThread();
    while (getSize().width <= 0) {
      try {
        anim.sleep(500);
      } catch (InterruptedException e) {
        return;
      }
    }

    Graphics2D g2d = null;
    Graphics2D BufferG2D = null;
    Graphics2D ScreenG2D = null;
    BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f);
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    int rule = AlphaComposite.SRC_OVER;
    AlphaComposite opaque = AlphaComposite.SrcOver;
    AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f);
    AlphaComposite set = AlphaComposite.Src;
    int frame = 0;
    int frametmp = 0;
    Dimension oldSize = getSize();
    Shape clippath = null;
    while (anim == me) {
      Dimension size = getSize();
      if (size.width != oldSize.width || size.height != oldSize.height) {
        img = null;
        clippath = null;
        if (BufferG2D != null) {
          BufferG2D.dispose();
          BufferG2D = null;
        }
        if (ScreenG2D != null) {
          ScreenG2D.dispose();
          ScreenG2D = null;
        }
      }
      oldSize = size;

      if (img == null) {
        img = (BufferedImage) createImage(size.width, size.height);
      }

      if (BufferG2D == null) {
        BufferG2D = img.createGraphics();
        BufferG2D.setRenderingHint(
            RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
        BufferG2D.setClip(clippath);
      }
      g2d = BufferG2D;

      float[] ctrlpts;
      for (int i = 0; i < animpts.length; i += 2) {
        animate(animpts, deltas, i + 0, size.width);
        animate(animpts, deltas, i + 1, size.height);
      }
      ctrlpts = animpts;
      int len = ctrlpts.length;
      gp.reset();
      int dir = 0;
      float prevx = ctrlpts[len - 2];
      float prevy = ctrlpts[len - 1];
      float curx = ctrlpts[0];
      float cury = ctrlpts[1];
      float midx = (curx + prevx) / 2.0f;
      float midy = (cury + prevy) / 2.0f;
      gp.moveTo(midx, midy);
      for (int i = 2; i <= ctrlpts.length; i += 2) {
        float x1 = (midx + curx) / 2.0f;
        float y1 = (midy + cury) / 2.0f;
        prevx = curx;
        prevy = cury;
        if (i < ctrlpts.length) {
          curx = ctrlpts[i + 0];
          cury = ctrlpts[i + 1];
        } else {
          curx = ctrlpts[0];
          cury = ctrlpts[1];
        }
        midx = (curx + prevx) / 2.0f;
        midy = (cury + prevy) / 2.0f;
        float x2 = (prevx + midx) / 2.0f;
        float y2 = (prevy + midy) / 2.0f;
        gp.curveTo(x1, y1, x2, y2, midx, midy);
      }
      gp.closePath();

      g2d.setComposite(set);
      g2d.setBackground(backgroundColor);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

      if (bgChanged || bounds == null) {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height
      // + 5);
      g2d.clearRect(0, 0, getWidth(), getHeight());

      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setColor(outerColor);
      g2d.setComposite(opaque);
      g2d.setStroke(solid);
      g2d.draw(gp);
      g2d.setPaint(gradient);

      if (!bgChanged) {
        bounds = gp.getBounds();
      } else {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      gradient =
          new GradientPaint(
              bounds.x,
              bounds.y,
              gradientColorA,
              bounds.x + bounds.width,
              bounds.y + bounds.height,
              gradientColorB,
              true);
      g2d.setComposite(blend);
      g2d.fill(gp);

      if (g2d == BufferG2D) {
        repaint();
      }
      ++frame;
      Thread.yield();
    }
    if (g2d != null) {
      g2d.dispose();
    }
  }
Пример #27
0
  /**
   * Do the filter operation
   *
   * @param src The source BufferedImage. Can be any type.
   * @param dst The destination image. If not null, must be of type TYPE_INT_RGB, TYPE_INT_ARGB or
   *     TYPE_INT_ARGB_PRE
   * @return the filtered image
   */
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();

    BufferedImageConsumer consumer = new BufferedImageConsumer(dst);

    ImageFilter fltr = filter.getFilterInstance(consumer);
    fltr.setDimensions(width, height);

    /*
    ColorModel cm = src.getColorModel();
    if (cm.getPixelSize() == 8) {
        // byte. indexed or gray:
        WritableRaster raster = src.getRaster();
        byte pixels[] = new byte[width];
        // calculate scanline by scanline in order to safe memory.
        // It also seems to run faster like that
        for (int y = 0; y < height; y++) {
            raster.getDataElements(0, y, width, 1, pixels);
            fltr.setPixels(0, y, width, 1, cm, pixels, 0, width);
        }
    } else {
        // integer, use the simple rgb mode:
        WritableRaster raster = src.getRaster();
        int pixels[] = new int[width];
        // calculate scanline by scanline in order to safe memory.
        // It also seems to run faster like that
        for (int y = 0; y < height; y++) {
            raster.getDataElements(0, y, width, 1, pixels);
            fltr.setPixels(0, y, width, 1, cm, pixels, 0, width);
        }
    }
    */

    // Always work in integer mode. this is more effective, and most
    // filters convert to integer internally anyhow
    ColorModel cm = new SimpleColorModel();

    // Create a BufferedImage of only 1 pixel height for fetching the rows of the image in the
    // correct format (ARGB)
    // This speeds up things by more than factor 2, compared to the standard BufferedImage.getRGB
    // solution,
    // which is supposed to be fast too. This is probably the case because drawing to BufferedImages
    // uses
    // very optimized code which may even be hardware accelerated.
    BufferedImage row = new BufferedImage(width, 1, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = row.createGraphics();
    int pixels[] = ((DataBufferInt) row.getRaster().getDataBuffer()).getData();

    // Make sure alpha values do not add up for each row:
    g2d.setComposite(AlphaComposite.Src);
    // Calculate scanline by scanline in order to safe memory.
    // It also seems to run faster like that
    for (int y = 0; y < height; y++) {
      g2d.drawImage(src, null, 0, -y);
      // Now pixels contains the rgb values of the row y!
      // filter this row now:
      fltr.setPixels(0, y, width, 1, cm, pixels, 0, width);
    }
    g2d.dispose();
    // The consumer now contains the filtered image, return it.
    return consumer.getImage();
  }
Пример #28
0
 /** [Advanced] */
 public void dispose() {
   Graphics2D g = getG();
   if (g != null) g.dispose();
 }
  protected void paintBackground(
      Graphics g, int x, int y, int w, int h, boolean horizontal, JComponent component) {
    Graphics2D g2d = (Graphics2D) g.create();
    CEclipseBorder ec = null;
    Insets ins = getOutsideInsets();

    x = ins.left;
    y = ins.top;
    if (getOrientation().isHorizontal()) {
      w -= ins.left + ins.right;
      h -= ins.top + ins.bottom;
    } else {
      w -= ins.top + ins.bottom;
      h -= ins.left + ins.right;
    }

    if (component.getBorder() instanceof CompoundBorder) {
      CompoundBorder cb = (CompoundBorder) component.getBorder();
      CompoundBorder bb = (CompoundBorder) cb.getInsideBorder();

      ec = (CEclipseBorder) bb.getOutsideBorder();
    }

    if (w > 0 && h > 0) {
      if (glassStrip != null) {
        BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        Graphics2D gg = im.createGraphics();
        gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        gg.setColor(component.getBackground());
        if (ec != null) {
          gg.fill(ec.createShape(0, 0, w, h, ec.getCornerRadius()));

        } else {
          gg.fillRect(0, 0, w, h);
        }

        if (!isSelected()) {
          gg.setComposite(AlphaComposite.SrcIn);
        } else {
          gg.setComposite(AlphaComposite.SrcAtop);
        }

        try {
          glass.Render2Graphics(new Dimension(w, h), gg, glassStrip, true);
        } catch (Exception e) {
          glass.Render2Graphics(new Dimension(w, h), gg, CGlassFactory.VALUE_STEEL, true);
        }

        gg.dispose();

        if (!getOrientation().isHorizontal()) {
          AffineTransform atTrans = AffineTransform.getTranslateInstance(x /* + h */, y + w);
          atTrans.concatenate(COutlineHelper.tRot90CCW);
          g2d.drawImage(im, atTrans, null);
        } else {
          g2d.drawImage(im, x, y, null);
        }
      }

      g2d.dispose();
    }
  }