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


Java Graphics2D.setRenderingHint方法代码示例

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


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

示例1: createBufferedImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage createBufferedImage(final boolean  aa) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.rotate(Math.toRadians(90));
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f));
    bg.drawString("MMMMMMMMMMMMMMMM", 0, 0);
    bg.dispose();
    return bi;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:DrawRotatedString.java

示例2: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Paints the JLabel.
 *
 * @param g
 */
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    myPath.moveTo(xx[0], yy[0]);
    myPath.lineTo(xx[0], yy[0]);
    myPath.lineTo(xx[1], yy[1]);
    myPath.lineTo(xx[2], yy[2]);
    myPath.closePath();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setPaint(GRADIENT_PAINT);
    g2.fill(myPath);
    myPath.reset();
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-B,代码行数:21,代码来源:GraphicsJLabel.java

示例3: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics g) {
    if (antiAlias) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        /*g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);*/
        super.paint(g2);
    } else {
        super.paint(g);
    }
}
 
开发者ID:ser316asu,项目名称:SER316-Dresden,代码行数:17,代码来源:HTMLEditorPane.java

示例4: alloySaveAsPNG

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Export the current drawing as a PNG file with the given file name and
 * image resolution.
 */
public void alloySaveAsPNG(String filename, double scale, double dpiX, double dpiY) throws IOException {
	try {
		int width = (int) (graph.getTotalWidth() * scale);
		if (width < 10)
			width = 10;
		int height = (int) (graph.getTotalHeight() * scale);
		if (height < 10)
			height = 10;
		BufferedImage bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		Graphics2D gr = (Graphics2D) (bf.getGraphics());
		gr.setColor(WHITE);
		gr.fillRect(0, 0, width, height);
		gr.setColor(BLACK);
		gr.scale(scale, scale);
		gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		graph.draw(new Artist(gr), scale, null, false);
		OurPNGWriter.writePNG(bf, filename, dpiX, dpiY);
	} catch (Throwable ex) {
		if (ex instanceof IOException)
			throw (IOException) ex;
		throw new IOException("Failure writing the PNG file to " + filename + " (" + ex + ")");
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:28,代码来源:GraphViewer.java

示例5: createImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Creates an BufferedImage and draws a text, using two transformations,
 * one for graphics and one for font.
 */
private static BufferedImage createImage(final boolean aa,
                                         final AffineTransform gtx,
                                         final AffineTransform ftx) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE, TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.transform(gtx);
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f).deriveFont(ftx));
    bg.drawString(STR, 0, 0);
    bg.dispose();
    return bi;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:DrawRotatedStringUsingRotatedFont.java

示例6: pintarLinhaEvento

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void pintarLinhaEvento(Graphics2D g2, Point origem, Point destino) {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
    g2.setColor(Color.red);
    g2.drawLine(origem.x, origem.y, destino.x, destino.y);
    g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
    g2.drawOval(destino.x - 25, destino.y - 25, 50, 50);
    g2.fillOval(destino.x - 10, destino.y - 10, 20, 20);
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:10,代码来源:PartidaView.java

示例7: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
	if (AppPreferences.ANTI_ALIASING.getBoolean()) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}
	super.paintComponent(g);
	drawText(g, 10, 20);
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:11,代码来源:About.java

示例8: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
    Graphics2D g2 = (Graphics2D)g;
    
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON );
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                        RenderingHints.VALUE_RENDER_QUALITY );

    g.setColor(BloxsColors.$BACKGROUND);
    g.fillRect(0, 0, getWidth(), getHeight());
    
    drawLast.clear();
    
    Rectangle result = new Rectangle();
    for (int i = 0; i < elements.size(); i++) {
        Element get = elements.get(i);
        result=get.draw((Graphics2D) g).union(result);
    }
    
    //System.out.println("Size: "+drawLast.size());
    for (int i = 0; i < drawLast.size(); i++) {
        result=drawLast.get(i).draw((Graphics2D) g).union(result);    
    }
    
    /*
    g.setColor(Color.RED);
    g.drawRect(result.x, result.y, result.width, result.height);
    */
    setPreferredSize(new Dimension(result.x+result.width, result.y+result.height));
    revalidate();
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:34,代码来源:BloxsEditor.java

示例9: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    final float POINTS = 9;
    final float SIZE = 8;

    Graphics2D g2 = (Graphics2D) g.create();
    g2.setColor(Color.BLUE);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    long time = gTime;
    gTime += 1;
    time %= POINTS + 1;

    double angle = time / (POINTS + 1) * Math.PI * 2.0;

    double w = getWidth();
    double h = getHeight();

    for (int i = 0; i < POINTS; i++) {
        double x = Math.sin(angle);
        double y = -Math.cos(angle);

        angle += Math.PI * 2.0 / (POINTS + 1);

        float strength = 1f - (POINTS - i - 1) / POINTS;
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, strength));

        double mx = w / 2 + x * w * (SIZE - 2) / SIZE / 2.0;
        double my = h / 2 + y * h * (SIZE - 2) / SIZE / 2.0;

        g2.fillOval((int) (mx - w / SIZE / 2), (int) (my - h / SIZE / 2), (int) (w / SIZE), (int) (h / SIZE));
    }

    g2.dispose();
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:36,代码来源:StartupPanel.java

示例10: scaleBufferedImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage scaleBufferedImage(BufferedImage p_scaleBufferedImage_0_, int p_scaleBufferedImage_1_, int p_scaleBufferedImage_2_)
{
    BufferedImage bufferedimage = new BufferedImage(p_scaleBufferedImage_1_, p_scaleBufferedImage_2_, 2);
    Graphics2D graphics2d = bufferedimage.createGraphics();
    graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2d.drawImage(p_scaleBufferedImage_0_, 0, 0, p_scaleBufferedImage_1_, p_scaleBufferedImage_2_, (ImageObserver)null);
    return bufferedimage;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:9,代码来源:TextureAnimations.java

示例11: paintSelectedTop

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void paintSelectedTop(Graphics g, int x, int y, int w, int h) {
	Graphics2D g2 = (Graphics2D) g.create();
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	drawTopTab(x, y, w, h, g2, Colors.TAB_BACKGROUND_SELECTED);

	g2.dispose();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:9,代码来源:TabbedPaneUI.java

示例12: resizeImageWithHint

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type, int IMG_WIDTH, int IMG_HEIGHT) {

		BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
		Graphics2D g = resizedImage.createGraphics();
		g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
		g.dispose();
		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);

		return resizedImage;
	}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:15,代码来源:Convolution.java

示例13: createContext

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public PaintContext createContext(ColorModel cm,
                                  Rectangle deviceBounds,
                                  Rectangle2D userBounds,
                                  AffineTransform at,
                                  RenderingHints hints) {

    // Fill bufferedImage using
    final Graphics2D g2d = (Graphics2D) getImage().getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setBackground(Color.PINK);
        g2d.clearRect(0, 0, size, size);

        g2d.setColor(Color.BLUE);
        g2d.drawRect(0, 0, size, size);

        g2d.fillOval(size / 10, size / 10,
                     size * 8 / 10, size * 8 / 10);

    } finally {
        g2d.dispose();
    }

    return super.createContext(cm, deviceBounds, userBounds, at, hints);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:CrashPaintTest.java

示例14: renderTo

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void renderTo(BufferedImage dst) {
    System.out.println("The buffer: " + dst);
    Graphics2D g = dst.createGraphics();

    final int w = dst.getWidth();
    final int h = dst.getHeight();

    g.setColor(Color.blue);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.red);
    Font f = g.getFont();
    g.setFont(f.deriveFont(48f));

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // NB: this clip ctriggers the problem
    g.setClip(50, 50, 200, 100);

    g.drawString("AA Text", 52, 90);

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

    // NB: this clip ctriggers the problem
    g.setClip(50, 100, 100, 100);
    g.drawString("Text", 52, 148);

    g.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:RenderToCustomBufferTest.java

示例15: unrotate

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage unrotate(BufferedImage img, double angle, int origw, int origh, boolean subpixel, boolean fast) {

		img = rotate(img, 360 - (angle % 360), fast);

		int startx = (img.getWidth()-origw)/2;
		int starty = (img.getHeight()-origh)/2;

		int extra = (img.getWidth() - origw) >2 ? 1 : 0;

		img = img.getSubimage(startx, starty, origw + extra, origh + extra);

		AffineTransform t = new AffineTransform();

		if(subpixel) {
			double xerr = 0, yerr = 0;
			for(int x = 0; x < img.getWidth(); x++)
				xerr += ImageTools.getAlpha(img.getRGB(x, 0));
			for(int y = 0; y < img.getHeight(); y++)
				yerr += ImageTools.getAlpha(img.getRGB(0, y));

			xerr /= (img.getWidth() * 255);
			xerr = 1 - xerr;
			yerr /= (img.getHeight() * 255);
			yerr = 1 - yerr;
			t.translate(-yerr, -xerr);
		}

		BufferedImage ret = new BufferedImage(origw, origh, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = ret.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

		g.drawImage(img, t, null);
		g.dispose();

		return ret;
	}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:38,代码来源:ImageTools.java


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