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


Java Graphics2D.setComposite方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.setComposite方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setComposite方法的具体用法?Java Graphics2D.setComposite怎么用?Java Graphics2D.setComposite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


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

示例1: drawDragArea

import java.awt.Graphics2D; //导入方法依赖的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

示例2: paintGroup

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintGroup(Graphics2D g, Group selection) {
    super.paintGroup(g, selection);
    Bounds[] bounds = selection.getBounds();
    g.setComposite(instance);
    if (bounds.length > 0) {
        Component component = getComponent(bounds[0]);
        try {
            if (((XMLComponent) component).isY())
                paintYShow(g, selection.getTranslate().getY(), bounds[0]);
            else
                paintXShow(g, selection.getTranslate().getX(), bounds[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:18,代码来源:XMLDiagram.java

示例3: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 *
 */
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);
    }
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:25,代码来源:mxGraphHandler.java

示例4: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    if (!isEnabled()) {
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.3f));
    }                
    Color oldColor = g.getColor();
    Dimension size = getSize();
    g.setColor(getBackground());
    g.fillRect(0, 0, size.width, size.height);
    int i = (size.height - SIZE) / 2;
    if (value.color != null) {
        g.setColor(Color.black);
        g.drawRect(i, i, SIZE, SIZE);
        g.setColor(value.color);
        g.fillRect(i + 1, i + 1, SIZE - 1, SIZE - 1);
    }
    if (value.text != null) {
        g.setColor(Color.black);
        if (value.color != null)
            g.drawString(value.text, i + SIZE + 5, i + SIZE);
        else
            g.drawString(value.text, 5, i + SIZE);
    }
    g.setColor(oldColor);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:SplashUISupport.java

示例5: graphicsImage

import java.awt.Graphics2D; //导入方法依赖的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

示例6: PinteRegiao

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void PinteRegiao(Graphics2D g) {
    Composite originalComposite = g.getComposite();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));
    g.setPaint(this.getForeColor());

    if (isGradiente()) {
        int dist = 0;
        int w = getWidth() - dist;
        int h = getHeight() - dist;
        int L = getLeft();
        int T = getTop();
        boolean dv = getGDirecao() == VERTICAL;

        GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true);
        g.setPaint(GP);
    }

    if (getTipoDesenho() != TipoDraw.tpTexto) {
        Stroke bkp = g.getStroke();
        if (isDashed()) {
            g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
        }
        if (isGradiente()) {
            g.fill(getRegiao());
        }
        g.draw(getRegiao()); //Pinta as eventuais linhas internas do dezenho. Ex. LivreVariosDocumemtos 

        g.setStroke(bkp);
    }
    g.setComposite(originalComposite);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:33,代码来源:LivreBase.java

示例7: fillBackground

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void fillBackground(Graphics2D g) {
   Graphics2D g2 = (Graphics2D) g.create();
   Rectangle2D window = new Rectangle2D.Double(0, 0, sw, sh);
   g2.setComposite(AlphaComposite.Clear);
   g2.fill(window);
   g2.dispose();
}
 
开发者ID:eric-roberts,项目名称:JavaPPTX,代码行数:8,代码来源:PPWindowImage.java

示例8: gridToTile

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void gridToTile(int tileX, int tileY, int level, File parent) throws IOException{
		double delta = levelZeroDelta / Math.pow(2, level);

//		double lon1 = lon0 + delta;
		double lat0 = getLatFromTileY(tileY, level, levelZeroDelta);
		double lat1 = lat0 + delta;

		int multiplier = getLonMultiplier(lat0, lat1);
		double lon0 = getLonFromTile(lat0, lat1, tileX, level, levelZeroDelta);
		double lon1 = lon0 + delta * multiplier;

		double[] tileWESN = new double[] {lon0, lon1, lat0, lat1};

		MapProjection proj = grid.getProjection();
		Point2D ul = proj.getMapXY(lon0, lat1);
		Point2D lr = proj.getMapXY(lon1, lat0);

		Rectangle bounds = new Rectangle();
		bounds.x = (int)Math.floor(ul.getX());
		bounds.y = (int)Math.floor(ul.getY());
		bounds.width = (int) Math.ceil(lr.getX()) - bounds.x;
		bounds.height = (int) Math.ceil(lr.getY()) - bounds.y;

		Grid2D subGrid = GridUtilities.getSubGrid(bounds, grid);
		BufferedImage tileImage = renderer.gridImage(subGrid).image;

//		System.out.println(bounds + "\t" + grid.getBounds());

		tileImage = imageProcessor.processImage(tileImage, tileWESN, tileWESN);

		BufferedImage scaledTileImage = new BufferedImage(TILE_SIZE, TILE_SIZE, tileImage.getType());
		Graphics2D g = scaledTileImage.createGraphics();
		g.setComposite(AlphaComposite.Src);
		g.drawImage(tileImage, 0, 0, TILE_SIZE, TILE_SIZE, null);

		StringBuffer sb = new StringBuffer();
		sb.append(tileY).append("_").append(tileX).append(".").append(outputFormat);

		ImageIO.write(scaledTileImage, outputFormat, new File(parent, sb.toString()));
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:41,代码来源:GridToWorldWindTiler.java

示例9: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Composite oldComposite = g2d.getComposite();
    Color oldColor = g2d.getColor();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, getWidth(), getHeight());
    g2d.setComposite(oldComposite);
    g2d.setColor(oldColor);

    super.paintComponent(g);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:14,代码来源:FreeColComboBoxRenderer.java

示例10: setup

import java.awt.Graphics2D; //导入方法依赖的package包/类
public Graphics setup(Graphics g) {
	float t;
	if (this.hovering) {
		t = getHoverTransparency();
	} else {
		t = getTransparency();
	}
	
	Graphics2D copy = (Graphics2D)g.create();
	copy.setComposite(AlphaComposite.getInstance(3, t));
	return copy;
}
 
开发者ID:DivergenceBot,项目名称:UpdateBuilder,代码行数:13,代码来源:TransparentComponent.java

示例11: getDestImage

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

示例12: drawFreeHandShape

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawFreeHandShape(SelectionShape selectionPoint, Graphics g)
{
	Graphics2D g2 = (Graphics2D) g;
	if(selectionPoint.isFreeHandSelectionConnected())
	{
		g2.setComposite(AlphaComposite.SrcOver.derive(0.7f));
		g2.setPaint(new Color(221, 0, 72));
	}
	for(int i = 0; i < selectionPoint.getFreeHandSelectionPointList().size(); i++)
	{
		Point point = selectionPoint.getFreeHandSelectionPointList().get(i);
		if(i < selectionPoint.getFreeHandSelectionPointList().size() - 1)
		{
			Point point2 = selectionPoint.getFreeHandSelectionPointList().get(i + 1);
			if(i == selectionPoint.getFreeHandSelectionPointList().size() - 1 || i == 0)
			{
				g2.setStroke(new BasicStroke(6));
			}
			else
			{
				g2.setStroke(new BasicStroke(2));
			}
			g2.drawLine(point.x, point.y, point2.x, point2.y);
		}
		
	}
	g2.dispose();
}
 
开发者ID:scriptkittie,项目名称:GlitchKernel,代码行数:29,代码来源:SelectionManager.java

示例13: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g1) {
	Graphics2D g = (Graphics2D) g1;

	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, Main.config.getBackgroundOpacity()));
	g.setColor(Main.config.getBackgroundColor());
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
	g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	BufferedImage colorImage = isActive() ? ColorManager.pressed : ColorManager.unpressed;
	g.drawImage(colorImage, 2, 2, this.getWidth() - 2, this.getHeight() - 2, 0, 0, colorImage.getWidth(), colorImage.getHeight(), this);

	g.setColor(isActive() ? Main.config.getBackgroundColor() : Main.config.getForegroundColor());

	String titleString = getTitle();
	Font titleFont = Main.config.mode.getTitleFont(titleString);
	Point namePos = Main.config.mode.getTitleDrawPosition(g, this, titleString, titleFont);
	g.setFont(titleFont);
	g.drawString(titleString, namePos.x, namePos.y);

	String valueString = getValue();
	Font valueFont = Main.config.mode.getValueFont(valueString);
	Point keyCountPos = Main.config.mode.getValueDrawPosition(g, this, valueString, valueFont);
	g.setFont(valueFont);
	g.drawString(valueString, keyCountPos.x, keyCountPos.y);
}
 
开发者ID:RoanH,项目名称:KeysPerSecond,代码行数:28,代码来源:BasePanel.java

示例14: clear

import java.awt.Graphics2D; //导入方法依赖的package包/类
static void clear(Graphics2D  g, int type, int w, int h) {
    Graphics2D gg = (Graphics2D) g.create();
    if (type > OPAQUE) {
        gg.setColor(new Color(0, 0, 0, 0));
        gg.setComposite(AlphaComposite.Src);
    } else {
        gg.setColor(new Color(0xAD, 0xD8, 0xE6));
    }
    gg.fillRect(0, 0, w, h);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:NonOpaqueDestLCDAATest.java

示例15: featherDragImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private BufferedImage featherDragImage(BufferedImage src,
                                         int w, int h, int b) {
// FIXME: duplicated from PieceMover!
      final BufferedImage dst =
        ImageUtils.createCompatibleTranslucentImage(w, h);

      final Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);

      // paint the rectangle occupied by the piece at specified alpha
      g.setColor(new Color(0xff, 0xff, 0xff, CURSOR_ALPHA));
      g.fillRect(0, 0, w, h);

      // feather outwards
      for (int f = 0; f < b; ++f) {
        final int alpha = CURSOR_ALPHA * (f + 1) / b;
        g.setColor(new Color(0xff, 0xff, 0xff, alpha));
        g.drawRect(f, f, w-2*f, h-2*f);
      }

      // paint in the source image
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
      g.drawImage(src, 0, 0, null);
      g.dispose();

      return dst;
    }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:29,代码来源:SetupStack.java


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