Java 类java.awt.AlphaComposite 实例源码

项目:openjdk-jdk10    文件:DrawImage.java   
/**
 * Return a non-accelerated BufferedImage of the requested type with the
 * indicated subimage of the original image located at 0,0 in the new image.
 * If a bgColor is supplied, composite the original image over that color
 * with a SrcOver operation, otherwise make a SrcNoEa copy.
 * <p>
 * Returned BufferedImage is not accelerated for two reasons:
 * <ul>
 * <li> Types of the image and surface are predefined, because these types
 *      correspond to the TransformHelpers, which we know we have. And
 *      acceleration can change the type of the surface
 * <li> Image will be used only once and acceleration caching wouldn't help
 * </ul>
 */
private BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
                                        int sx1, int sy1, int sx2, int sy2)
{
    final int width = sx2 - sx1;
    final int height = sy2 - sy1;
    final BufferedImage bimg = new BufferedImage(width, height, type);
    final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    bimg.setAccelerationPriority(0);
    if (bgColor != null) {
        g2d.setColor(bgColor);
        g2d.fillRect(0, 0, width, height);
        g2d.setComposite(AlphaComposite.SrcOver);
    }
    g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
    g2d.dispose();
    return bimg;
}
项目:jdk8u-jdk    文件:ImageTests.java   
public void modifyTest(TestEnvironment env) {
    int size = env.getIntValue(sizeList);
    Image src = tsit.getImage(env, size, size);
    Graphics g = src.getGraphics();
    if (hasGraphics2D) {
        ((Graphics2D) g).setComposite(AlphaComposite.Src);
    }
    if (size == 1) {
        g.setColor(colorsets[transparency][4]);
        g.fillRect(0, 0, 1, 1);
    } else {
        int mid = size/2;
        g.setColor(colorsets[transparency][0]);
        g.fillRect(0, 0, mid, mid);
        g.setColor(colorsets[transparency][1]);
        g.fillRect(mid, 0, size-mid, mid);
        g.setColor(colorsets[transparency][2]);
        g.fillRect(0, mid, mid, size-mid);
        g.setColor(colorsets[transparency][3]);
        g.fillRect(mid, mid, size-mid, size-mid);
    }
    g.dispose();
    env.setSrcImage(src);
}
项目:incubator-netbeans    文件:BalloonManager.java   
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;

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

    Composite oldC = g2d.getComposite();
    Shape s = getMask( getWidth(), getHeight() );

    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f*currentAlpha ) );
    g2d.setColor( Color.black );
    g2d.fill( getShadowMask(s) );

    g2d.setColor( UIManager.getColor( "ToolTip.background" ) ); //NOI18N
    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, currentAlpha ) );
    Point2D p1 = s.getBounds().getLocation();
    Point2D p2 = new Point2D.Double(p1.getX(), p1.getY()+s.getBounds().getHeight());
    if( isMouseOverEffect )
        g2d.setPaint( new GradientPaint( p2, getMouseOverGradientStartColor(), p1, getMouseOverGradientFinishColor() ) );
    else
        g2d.setPaint( new GradientPaint( p2, getDefaultGradientStartColor(), p1, getDefaultGradientFinishColor() ) );
    g2d.fill(s);
    g2d.setColor( Color.black );
    g2d.draw(s);
    g2d.setComposite( oldC );
}
项目:openjdk-jdk10    文件:IncorrectClipSurface2SW.java   
private static void draw(Shape clip, Shape to, Image vi, BufferedImage bi,
                         int scale) {
    Graphics2D big = bi.createGraphics();
    big.setComposite(AlphaComposite.Src);
    big.setClip(clip);
    Rectangle toBounds = to.getBounds();
    int x1 = toBounds.x;

    int y1 = toBounds.y;
    int x2 = x1 + toBounds.width;
    int y2 = y1 + toBounds.height;
    big.drawImage(vi, x1, y1, x2, y2, 0, 0, toBounds.width / scale,
                  toBounds.height / scale, null);
    big.dispose();
    vi.flush();
}
项目:jdk8u-jdk    文件:PeekMetrics.java   
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
项目:jmt    文件:Convex2DGraph.java   
/**
 * It draw a temporary point when a point is moved in another place
 * 
 * @param g
 *            The graphic object
 * @param p
 *            The position of the point
 * @param c
 *            The color of the point
 * @param size
 *            The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
    g.setColor(c);

    int fontSize = 7 + getPointSize();
    Font f = new Font("Arial", Font.PLAIN, fontSize);
    g.setFont(f);
    double x = Math.max(p.getX(), GRAPH_LEFT_MARGIN);
    double y = Math.min(p.getY(), getHeight() - GRAPH_BOTTOM_MARGIN);

    g.drawString("(" + FORMAT_3_DEC.format(getTrueX(x)) + ", "
            + FORMAT_3_DEC.format(getTrueY(y)) + ")",
            (int) (x - (fontSize * 3)), (int) y - 5 - getPointSize());

    g.drawOval((int) x - (((size / 2))), (int) y - (((size / 2))), size,
            size);

    g.setColor(Color.GRAY);
    Composite oldComp = g.getComposite();
    Composite alphaComp = AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, 0.3f);
    g.setComposite(alphaComp);
    g.fillOval((int) x - (((size / 2))), (int) y - (((size / 2))), size,
            size);
    g.setComposite(oldComp);
}
项目:jmt    文件:PainterConvex2D.java   
/**
 * Draw a semi-trasparet area
 * @param g The graphic object
 * @param dragPoint The first point
 * @param beginPoint The second point
 * @param c The color of the area
 */
public void drawDragArea(Graphics2D g, Point dragPoint, Point beginPoint, Color c) {
    g.setColor(c);

    Polygon poly = new Polygon();

    poly.addPoint((int) beginPoint.getX(), (int) beginPoint.getY());
    poly.addPoint((int) beginPoint.getX(), (int) dragPoint.getY());
    poly.addPoint((int) dragPoint.getX(), (int) dragPoint.getY());
    poly.addPoint((int) dragPoint.getX(), (int) beginPoint.getY());

    //Set the widths of the shape's outline
    Stroke oldStro = g.getStroke();
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g.setStroke(stroke);
    g.drawPolygon(poly);
    g.setStroke(oldStro);

    //Set the trasparency of the iside of the rectangle
    Composite oldComp = g.getComposite();
    Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
    g.setComposite(alphaComp);
    g.fillPolygon(poly);
    g.setComposite(oldComp);

}
项目:BasicsProject    文件:GifCaptcha.java   
/**
 * 画随机码图
 * @param fontcolor 随机字体颜色
 * @param strs 字符数组
 * @param flag 透明度使用
 * @return BufferedImage
 */
private BufferedImage graphicsImage(Color[] fontcolor,char[] strs,int flag)
{
    BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
    //或得图形上下文
    //Graphics2D g2d=image.createGraphics();
    Graphics2D g2d = (Graphics2D)image.getGraphics();
    //利用指定颜色填充背景
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, width, height);
    AlphaComposite ac3;
    int h  = height - ((height - font.getSize()) >>1) ;
    int w = width/len;
    g2d.setFont(font);
    for(int i=0;i<len;i++)
    {
        ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(flag, i));
        g2d.setComposite(ac3);
        g2d.setColor(fontcolor[i]);
        g2d.drawOval(num(width), num(height), 5+num(10), 5+num(10));
        g2d.drawString(strs[i]+"", (width-(len-i)*w)+(w-font.getSize())+1, h-4);
    }
    g2d.dispose();
    return image;
}
项目:smile_1.5.0_java7    文件:Graphics.java   
/**
 * Fill polygon. The coordinates are in logical coordinates. This also supports
 * basic alpha compositing rules for combining source and destination
 * colors to achieve blending and transparency effects with graphics and images.
 *
 * @param alpha the constant alpha to be multiplied with the alpha of the
 *     source. alpha must be a floating point number in the inclusive range
 *     [0.0, 1.0].
 */
public void fillPolygon(float alpha, double[]... coord) {
    int[][] c = new int[coord.length][2];
    for (int i = 0; i < coord.length; i++) {
        c[i] = projection.screenProjection(coord[i]);
    }

    int[] x = new int[c.length];
    for (int i = 0; i < c.length; i++) {
        x[i] = c[i][0];
    }
    int[] y = new int[c.length];
    for (int i = 0; i < c.length; i++) {
        y[i] = c[i][1];
    }

    Composite cs = g2d.getComposite();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));

    g2d.fillPolygon(x, y, c.length);

    g2d.setComposite(cs);
}
项目:sbc-qsystem    文件:FInfoDialog.java   
private Image resizeToBig(Image originalImage, int biggerWidth, int biggerHeight) {
    final BufferedImage resizedImage = new BufferedImage(biggerWidth, biggerHeight,
        BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = resizedImage.createGraphics();

    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.drawImage(originalImage, 0, 0, biggerWidth, biggerHeight, this);
    g.dispose();

    return resizedImage;
}
项目:OpenJSharp    文件:SunGraphics2D.java   
final void validateColor() {
    int eargb;
    if (imageComp == CompositeType.Clear) {
        eargb = 0;
    } else {
        eargb = foregroundColor.getRGB();
        if (compositeState <= COMP_ALPHA &&
            imageComp != CompositeType.SrcNoEa &&
            imageComp != CompositeType.SrcOverNoEa)
        {
            AlphaComposite alphacomp = (AlphaComposite) composite;
            int a = Math.round(alphacomp.getAlpha() * (eargb >>> 24));
            eargb = (eargb & 0x00ffffff) | (a << 24);
        }
    }
    this.eargb = eargb;
    this.pixel = surfaceData.pixelFor(eargb);
}
项目:VASSAL-src    文件:SymbolSet.java   
/**
 * Get image corresponding to this symbol. Generates the image and applies
 * optional mask if not already done so.
 * @param rect2 width and height are taken from this for otherwise invalid masks
 */
private BufferedImage getImage(Rectangle rect2) {
  if (img == null) {
    if ( isMask && (rect.width <= 0 || rect.height <= 0
        || rect.width+rect.x > bitmap.getWidth()
        || rect.height+rect.y > bitmap.getHeight() )) {
      // Images with invalid masks appear to be completely transparent.
      // This is a hassle generating new ones all the time, but there's nothing
      // to say that the real mask can't be different sizes at every call,
      // and anything else seems like overkill -- so this is an ugly kludge.
      // Hopefully, this crime against nature doesn't happen very often.
      return new BufferedImage(rect2.width, rect2.height, BufferedImage.TYPE_INT_ARGB);
    }
    img = bitmap.getSubimage(rect.x, rect.y, rect.width, rect.height);
    if (getMask() != null) {
      final BufferedImage bi = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_ARGB);
      final Graphics2D g = bi.createGraphics();
      g.drawImage(img, null, 0, 0);
      g.setComposite(AlphaComposite.DstAtop);
      g.drawImage(getMask().getImage(rect), null, 0, 0);
      img = bi;
    }
  }
  return img;
}
项目:openjdk-jdk10    文件:UnmanagedDrawImagePerformance.java   
private static long test(Image bi, Image vi, AffineTransform atfm) {
    final Polygon p = new Polygon();
    p.addPoint(0, 0);
    p.addPoint(SIZE, 0);
    p.addPoint(0, SIZE);
    p.addPoint(SIZE, SIZE);
    p.addPoint(0, 0);
    Graphics2D g2d = (Graphics2D) vi.getGraphics();
    g2d.clip(p);
    g2d.transform(atfm);
    g2d.setComposite(AlphaComposite.SrcOver);
    final long start = System.nanoTime();
    g2d.drawImage(bi, 0, 0, null);
    final long time = System.nanoTime() - start;
    g2d.dispose();
    return time;
}
项目:TrabalhoFinalEDA2    文件:mxUtils.java   
/**
 * Clears the given area of the specified graphics object with the given
 * color or makes the region transparent.
 */
public static void clearRect(Graphics2D g, Rectangle rect, Color background)
{
    if (background != null)
    {
        g.setColor(background);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    }
    else
    {
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,
                0.0f));
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
        g.setComposite(AlphaComposite.SrcOver);
    }
}
项目:VASSAL-src    文件:WizardSupport.java   
public void setBackgroundImage(Image image) {
  if (image != null) {
    final ImageIcon icon = new ImageIcon(image);
    logoSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
    final BufferedImage img =
      ImageUtils.createCompatibleTranslucentImage(logoSize.width,
                                                  logoSize.height);
    Graphics2D g = img.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    UIManager.put("wizard.sidebar.image", img); //$NON-NLS-1$
  }
}
项目:brModelo    文件:Tabela.java   
private void FillCampos(Graphics2D g, Rectangle r, boolean normal) {
    Composite originalComposite = g.getComposite();
    float alfa = 1f - getAlfa();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));
    Paint bkpp = g.getPaint();
    g.setColor(getMaster().getBackground()); //# Não: isDisablePainted()? disabledColor : 
    if (!normal) {
        if (isGradiente()) {
            g.setColor(getGradienteStartColor());
        } else {
            g.setColor(getForeColor());
        }
    }
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlfa()));
    g.fill(r);

    g.setPaint(bkpp);
    g.setComposite(originalComposite);
}
项目:StreamDeckCore    文件:IconHelper.java   
public static BufferedImage createResizedCopy(BufferedImage originalImage) {
    int scaledWidth = StreamDeck.ICON_SIZE;
    int scaledHeight = StreamDeck.ICON_SIZE;
    if (originalImage.getWidth() != originalImage.getHeight()) {
        float scalerWidth = ((float) StreamDeck.ICON_SIZE) / originalImage.getWidth();
        float scalerHeight = ((float) StreamDeck.ICON_SIZE) / originalImage.getWidth();
        if (scalerWidth < scaledHeight)
            scaledHeight = Math.round(scalerWidth * originalImage.getHeight());
        else
            scaledWidth = Math.round(scalerHeight * originalImage.getWidth());

    }
    int imageType = BufferedImage.TYPE_INT_ARGB;
    BufferedImage scaledBI = new BufferedImage(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE, imageType);
    Graphics2D g = scaledBI.createGraphics();
    if (true) {
        g.setComposite(AlphaComposite.Src);
    }
    g.drawImage(originalImage, (StreamDeck.ICON_SIZE - scaledWidth) / 2, (StreamDeck.ICON_SIZE - scaledHeight) / 2,
            scaledWidth, scaledHeight, null);
    g.dispose();
    return scaledBI;
}
项目:parabuild-ci    文件:Plot.java   
/**
 * Draws the background image (if there is one) aligned within the 
 * specified area.
 * 
 * @param g2  the graphics device.
 * @param area  the area.
 * 
 * @see #getBackgroundImage()
 * @see #getBackgroundImageAlignment()
 * @see #getBackgroundImageAlpha()
 */
protected void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundImage != null) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
                this.backgroundImageAlpha));
        Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0,
                this.backgroundImage.getWidth(null), 
                this.backgroundImage.getHeight(null));
        Align.align(dest, area, this.backgroundImageAlignment);
        g2.drawImage(this.backgroundImage, (int) dest.getX(), 
                (int) dest.getY(), (int) dest.getWidth() + 1, 
                (int) dest.getHeight() + 1, null);
        g2.setComposite(originalComposite);
    }
}
项目:QN-ACTR-Release    文件:PainterConvex2D.java   
/**
 * Draw a semi-trasparet area
 * @param g The graphic object
 * @param dragPoint The first point
 * @param beginPoint The second point
 * @param c The color of the area
 */
public void drawDragArea(Graphics2D g, Point dragPoint, Point beginPoint, Color c) {
    g.setColor(c);

    Polygon poly = new Polygon();

    poly.addPoint((int) beginPoint.getX(), (int) beginPoint.getY());
    poly.addPoint((int) beginPoint.getX(), (int) dragPoint.getY());
    poly.addPoint((int) dragPoint.getX(), (int) dragPoint.getY());
    poly.addPoint((int) dragPoint.getX(), (int) beginPoint.getY());

    //Set the widths of the shape's outline
    Stroke oldStro = g.getStroke();
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g.setStroke(stroke);
    g.drawPolygon(poly);
    g.setStroke(oldStro);

    //Set the trasparency of the iside of the rectangle
    Composite oldComp = g.getComposite();
    Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
    g.setComposite(alphaComp);
    g.fillPolygon(poly);
    g.setComposite(oldComp);

}
项目:openjdk-jdk10    文件:SunGraphics2D.java   
void validateColor() {
    int eargb;
    if (imageComp == CompositeType.Clear) {
        eargb = 0;
    } else {
        eargb = foregroundColor.getRGB();
        if (compositeState <= COMP_ALPHA &&
            imageComp != CompositeType.SrcNoEa &&
            imageComp != CompositeType.SrcOverNoEa)
        {
            AlphaComposite alphacomp = (AlphaComposite) composite;
            int a = Math.round(alphacomp.getAlpha() * (eargb >>> 24));
            eargb = (eargb & 0x00ffffff) | (a << 24);
        }
    }
    this.eargb = eargb;
    this.pixel = surfaceData.pixelFor(eargb);
}
项目:BrainControl    文件:LevelRenderer.java   
public LevelRenderer(Level level, GraphicsConfiguration graphicsConfiguration, int width, int height) {
        this.width = width;
        this.height = height;

        this.level = level;
        image = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);

        g = (Graphics2D) image.getGraphics();
        g.setComposite(AlphaComposite.Src);

//      //ENABLE PARTIAL TRANSPARENCY FOR LEVEL (AND BACKGROUND?)
//      AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
//        g.setComposite(ac);       

        updateArea(0, 0, width, height);
    }
项目:Tarski    文件:mxGraphHandler.java   
/**
 *
 */
public void paint(Graphics g) {
  if (isVisible() && previewBounds != null) {
    if (dragImage != null) {
      // LATER: Clipping with mxUtils doesnt fix the problem
      // of the drawImage being painted over the scrollbars
      Graphics2D tmp = (Graphics2D) g.create();

      if (graphComponent.getPreviewAlpha() < 1) {
        tmp.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            graphComponent.getPreviewAlpha()));
      }

      tmp.drawImage(dragImage.getImage(), previewBounds.x, previewBounds.y,
          dragImage.getIconWidth(), dragImage.getIconHeight(), null);
      tmp.dispose();
    } else if (!imagePreview) {
      mxSwingConstants.PREVIEW_BORDER.paintBorder(graphComponent, g, previewBounds.x,
          previewBounds.y, previewBounds.width, previewBounds.height);
    }
  }
}
项目:geomapapp    文件:MaskToWorldWindTiler.java   
private static BufferedImage resizeImage(BufferedImage sample, double sampleMinLat, double sampleMaxLat, double tileMinLat, double tileMaxLat) {
    BufferedImage img = new BufferedImage(TILE_SIZE, TILE_SIZE, BufferedImage.TYPE_INT_ARGB);
    for (int x = 0; x < TILE_SIZE; x++)
        for (int y = 0; y < TILE_SIZE; y++)
            img.setRGB(x, y, 0x80000000);

    double tileScale = TILE_SIZE / (tileMinLat - tileMaxLat);

    // s for source; d for destination; all measurements in pixels
    int sx1 = 0;
    int sy1 = 0;
    int sx2 = sample.getWidth();
    int sy2 = sample.getHeight();

    int dx1 = 0;
    int dy1 = (int) ((sampleMaxLat - tileMaxLat) * tileScale);
    int dx2 = TILE_SIZE;
    int dy2 = (int) ((sampleMinLat - tileMaxLat) * tileScale);

    Graphics2D g = img.createGraphics();
    g.setComposite( AlphaComposite.Src );
    g.drawImage(sample, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);

    return img;
}
项目:openjdk-jdk10    文件:ImageTests.java   
public void modifyTest(TestEnvironment env) {
    int size = env.getIntValue(sizeList);
    Image src = tsit.getImage(env, size, size);
    Graphics g = src.getGraphics();
    if (hasGraphics2D) {
        ((Graphics2D) g).setComposite(AlphaComposite.Src);
    }
    if (size == 1) {
        g.setColor(colorsets[transparency][4]);
        g.fillRect(0, 0, 1, 1);
    } else {
        int mid = size/2;
        g.setColor(colorsets[transparency][0]);
        g.fillRect(0, 0, mid, mid);
        g.setColor(colorsets[transparency][1]);
        g.fillRect(mid, 0, size-mid, mid);
        g.setColor(colorsets[transparency][2]);
        g.fillRect(0, mid, mid, size-mid);
        g.setColor(colorsets[transparency][3]);
        g.fillRect(mid, mid, size-mid, size-mid);
    }
    g.dispose();
    env.setSrcImage(src);
}
项目:freecol    文件:DeclarationPanel.java   
/**
 * {@inheritDoc}
 */
@Override
public void paintComponent(Graphics g) {
    if (points == null || points.length == 0) {
        return;
    }
    if (isOpaque()) {
        super.paintComponent(g);
    }

    g.setColor(Color.BLACK);
    ((Graphics2D)g).setComposite(AlphaComposite
        .getInstance(AlphaComposite.SRC_OVER, 0.75f));

    for (int i = 0; i < counter-1; i++) {
        Point p1 = points[i];
        Point p2 = points[i+1];
        g.drawLine((int) p1.getX(), (int) p1.getY(),
            (int) p2.getX(), (int) p2.getY());
    }
}
项目:jdk8u-jdk    文件:DrawImage.java   
/**
 * Return a non-accelerated BufferedImage of the requested type with the
 * indicated subimage of the original image located at 0,0 in the new image.
 * If a bgColor is supplied, composite the original image over that color
 * with a SrcOver operation, otherwise make a SrcNoEa copy.
 * <p>
 * Returned BufferedImage is not accelerated for two reasons:
 * <ul>
 * <li> Types of the image and surface are predefined, because these types
 *      correspond to the TransformHelpers, which we know we have. And
 *      acceleration can change the type of the surface
 * <li> Image will be used only once and acceleration caching wouldn't help
 * </ul>
 */
BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
                                int sx1, int sy1, int sx2, int sy2)
{
    final int width = sx2 - sx1;
    final int height = sy2 - sy1;
    final BufferedImage bimg = new BufferedImage(width, height, type);
    final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    bimg.setAccelerationPriority(0);
    if (bgColor != null) {
        g2d.setColor(bgColor);
        g2d.fillRect(0, 0, width, height);
        g2d.setComposite(AlphaComposite.SrcOver);
    }
    g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
    g2d.dispose();
    return bimg;
}
项目:brModelo    文件:Desenhador.java   
public void DrawImagem(Graphics2D g) {
    BufferedImage imgB = getImagem();
    if (imgB == null) {
        return;
    }
    Rectangle rec = getBounds();
    rec.grow(-2, -2);
    if (imgres == null) {
        imgres = imgB.getScaledInstance(rec.width, rec.height, Image.SCALE_SMOOTH);
    }

    Composite originalComposite = g.getComposite();
    if (alfa != 1f) {
        int type = AlphaComposite.SRC_OVER;
        g.setComposite(AlphaComposite.getInstance(type, alfa));
    }
    Image img = imgres;
    if (isDisablePainted()) {
        img = util.Utilidades.dye(new ImageIcon(imgres), disabledColor);
    }

    g.drawImage(img, rec.x, rec.y, null);
    g.setComposite(originalComposite);
}
项目:OpenJSharp    文件:ImageTests.java   
public void modifyTest(TestEnvironment env) {
    int size = env.getIntValue(sizeList);
    Image src = tsit.getImage(env, size, size);
    Graphics g = src.getGraphics();
    if (hasGraphics2D) {
        ((Graphics2D) g).setComposite(AlphaComposite.Src);
    }
    if (size == 1) {
        g.setColor(colorsets[transparency][4]);
        g.fillRect(0, 0, 1, 1);
    } else {
        int mid = size/2;
        g.setColor(colorsets[transparency][0]);
        g.fillRect(0, 0, mid, mid);
        g.setColor(colorsets[transparency][1]);
        g.fillRect(mid, 0, size-mid, mid);
        g.setColor(colorsets[transparency][2]);
        g.fillRect(0, mid, mid, size-mid);
        g.setColor(colorsets[transparency][3]);
        g.fillRect(mid, mid, size-mid, size-mid);
    }
    g.dispose();
    env.setSrcImage(src);
}
项目:openvisualtraceroute    文件:GlassPane.java   
/**
 * @see javax.swing.JComponent#paint(java.awt.Graphics)
 */
@Override
public void paint(final Graphics g) {
    // transparent panel
    if (g instanceof Graphics2D) {
        ((Graphics2D) g).setComposite(AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.7f));
    }
    super.paint(g);
}
项目:jdk8u-jdk    文件:OpaqueImageToSurfaceBlitTest.java   
public static void main(String[] args) {

        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
        vi.validate(gc);

        BufferedImage bi =
            new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
        int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
        data[0] = 0x0000007f;
        data[1] = 0x0000007f;
        data[2] = 0xff00007f;
        data[3] = 0xff00007f;
        Graphics2D g = vi.createGraphics();
        g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
        g.drawImage(bi, 0, 0, null);

        bi = vi.getSnapshot();
        if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
            throw new RuntimeException("Test FAILED: color at 0x0 ="+
                Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
                Integer.toHexString(bi.getRGB(1,1)));
        }

        System.out.println("Test PASSED.");
    }
项目:litiengine    文件:OrthogonalMapRenderer.java   
/**
 * Gets the layer image.
 *
 * @param layer
 *          the layer
 * @param map
 *          the map
 * @return the layer image
 */
private synchronized BufferedImage getLayerImage(final ITileLayer layer, final IMap map, boolean includeAnimationTiles) {
  // if we have already retrived the image, use the one from the cache to
  // draw the layer
  final String cacheKey = MessageFormat.format("{0}_{1}", getCacheKey(map), layer.getName());
  if (ImageCache.MAPS.containsKey(cacheKey)) {
    return ImageCache.MAPS.get(cacheKey);
  }
  final BufferedImage bufferedImage = ImageProcessing.getCompatibleImage(layer.getSizeInTiles().width * map.getTileSize().width, layer.getSizeInTiles().height * map.getTileSize().height);

  // we need a graphics 2D object to work with transparency
  final Graphics2D imageGraphics = bufferedImage.createGraphics();

  // set alpha value of the tiles by the layers value
  final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
  imageGraphics.setComposite(ac);

  layer.getTiles().parallelStream().forEach(tile -> {
    // get the tile from the tileset image
    final int index = layer.getTiles().indexOf(tile);
    if (tile.getGridId() == 0) {
      return;
    }

    if (!includeAnimationTiles && MapUtilities.hasAnimation(map, tile)) {
      return;
    }

    final Image tileTexture = getTileImage(map, tile);

    // draw the tile on the layer image
    final int x = index % layer.getSizeInTiles().width * map.getTileSize().width;
    final int y = index / layer.getSizeInTiles().width * map.getTileSize().height;
    RenderEngine.renderImage(imageGraphics, tileTexture, x, y);
  });

  ImageCache.MAPS.put(cacheKey, bufferedImage);
  return bufferedImage;
}
项目:openjdk-jdk10    文件:EffectUtils.java   
/**
 * Clear a transparent image to 100% transparent
 *
 * @param img The image to clear
 */
static void clearImage(BufferedImage img) {
    Graphics2D g2 = img.createGraphics();
    g2.setComposite(AlphaComposite.Clear);
    g2.fillRect(0, 0, img.getWidth(), img.getHeight());
    g2.dispose();
}
项目:openjdk-jdk10    文件:CompositeType.java   
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
项目:OpenJSharp    文件:GraphicsPrimitive.java   
protected static void convertTo(Blit ob,
                                SurfaceData srcImg, SurfaceData dstImg,
                                Region clip,
                                int dstX, int dstY, int w, int h)
{
    if (ob != null) {
        ob.Blit(srcImg, dstImg, AlphaComposite.Src, clip,
                0, 0, dstX, dstY, w, h);
    }
}
项目:parabuild-ci    文件:Plot.java   
/**
 * Fills the specified area with the background paint.
 * 
 * @param g2  the graphics device.
 * @param area  the area.
 */
protected void fillBackground(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundPaint != null) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundAlpha)
        );
        g2.setPaint(this.backgroundPaint);
        g2.fill(area);
        g2.setComposite(originalComposite);
    }        
}
项目:incubator-netbeans    文件:AquaSlidingButtonUI.java   
@Override
protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
    Graphics2D g2d = (Graphics2D) g;

    Composite comp = g2d.getComposite();
    if( b.getModel().isRollover() || b.getModel().isSelected() ) {
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    }
    super.paintIcon(g, b, iconRect);
    g2d.setComposite(comp);
}
项目:openjdk-jdk10    文件:JPEGsNotAcceleratedTest.java   
public BufferedImage getDestImage() {
    BufferedImage destBI =
        new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D)destBI.getGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setColor(Color.blue);
    g.fillRect(0, 0, TEST_W, TEST_H);
    return destBI;
}
项目:OpenJSharp    文件:SunCompositeContext.java   
public SunCompositeContext(AlphaComposite ac,
                           ColorModel s, ColorModel d)
{
    if (s == null) {
        throw new NullPointerException("Source color model cannot be null");
    }
    if (d == null) {
        throw new NullPointerException("Destination color model cannot be null");
    }
    srcCM = s;
    dstCM = d;
    this.composite = ac;
    this.comptype = CompositeType.forAlphaComposite(ac);
}
项目:incubator-netbeans    文件:DnDSupport.java   
private BufferedImage createContentImage( JComponent c, Dimension contentSize ) {
    GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    boolean opaque = c.isOpaque();
    c.setOpaque(true);
    BufferedImage res = cfg.createCompatibleImage(contentSize.width, contentSize.height);
    Graphics2D g = res.createGraphics();
    g.setColor( c.getBackground() );
    g.fillRect(0, 0, contentSize.width, contentSize.height);
    g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f ));
    c.paint(g);
    c.setOpaque(opaque);
    return res;
}
项目:incubator-netbeans    文件:ScaleFx.java   
public void paint(Graphics g) {
    Rectangle bounds = getBounds();

    if (origImage == null) {
        if (comp == null) {
            return;
        }
        origImage = tryCreateImage();
        if (origImage == null) {
            return;
        }
    }
    Image img = origImage;
    Graphics2D g2d = (Graphics2D) g;
    Composite origComposite = g2d.getComposite();
    g2d.setComposite (AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    /*AffineTransform at = AffineTransform.getScaleInstance(
        (double)bounds.width / (double)scaleSource.width,
        (double)bounds.height / (double)scaleSource.height);
    g2d.setTransform(at);*/
    g2d.drawImage(img, 0, 0, bounds.width, bounds.height, null);
    //SwingUtilities.paintComponent(g, getComponent(0), this, 0, 0, bounds.width, bounds.height);
    //super.paint(g2d);

    if (origComposite != null) {
        g2d.setComposite(origComposite);
    }
}