当前位置: 首页>>代码示例>>Java>>正文


Java AlphaComposite类代码示例

本文整理汇总了Java中java.awt.AlphaComposite的典型用法代码示例。如果您正苦于以下问题:Java AlphaComposite类的具体用法?Java AlphaComposite怎么用?Java AlphaComposite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AlphaComposite类属于java.awt包,在下文中一共展示了AlphaComposite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawShadowPoint

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:38,代码来源:Convex2DGraph.java

示例2: makeBufferedImage

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:DrawImage.java

示例3: modifyTest

import java.awt.AlphaComposite; //导入依赖的package包/类
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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:ImageTests.java

示例4: paintComponent

import java.awt.AlphaComposite; //导入依赖的package包/类
@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 );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:BalloonManager.java

示例5: draw

import java.awt.AlphaComposite; //导入依赖的package包/类
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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IncorrectClipSurface2SW.java

示例6: checkAlpha

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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;
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:PeekMetrics.java

示例7: drawDragArea

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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);

}
 
开发者ID:max6cn,项目名称:jmt,代码行数:33,代码来源:PainterConvex2D.java

示例8: graphicsImage

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 画随机码图
 * @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;
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:32,代码来源:GifCaptcha.java

示例9: fillPolygon

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:32,代码来源:Graphics.java

示例10: resizeToBig

import java.awt.AlphaComposite; //导入依赖的package包/类
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;
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:17,代码来源:FInfoDialog.java

示例11: validateColor

import java.awt.AlphaComposite; //导入依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:SunGraphics2D.java

示例12: getImage

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:30,代码来源:SymbolSet.java

示例13: test

import java.awt.AlphaComposite; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:UnmanagedDrawImagePerformance.java

示例14: clearRect

import java.awt.AlphaComposite; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:20,代码来源:mxUtils.java

示例15: setBackgroundImage

import java.awt.AlphaComposite; //导入依赖的package包/类
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$
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:17,代码来源:WizardSupport.java


注:本文中的java.awt.AlphaComposite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。