概述
本文整理匯總了Java中java.awt.Graphics2D.setRenderingHint方法的典型用法代碼示例。如果您正苦於以下問題:Java Graphics2D.setRenderingHint方法的具體用法?Java Graphics2D.setRenderingHint怎麽用?Java Graphics2D.setRenderingHint使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Graphics2D的用法示例。
在下文中一共展示了Graphics2D.setRenderingHint方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: createBufferedImage
點讚 4
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,
示例2: paintComponent
點讚 3
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,
示例3: paint
點讚 3
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,
示例4: alloySaveAsPNG
點讚 3
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,
示例5: createImage
點讚 3
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,
示例6: pintarLinhaEvento
點讚 2
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,
示例7: paintComponent
點讚 2
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,
示例8: paintComponent
點讚 2
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,
示例9: paintComponent
點讚 2
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,
示例10: scaleBufferedImage
點讚 2
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,
示例11: paintSelectedTop
點讚 2
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,
示例12: resizeImageWithHint
點讚 2
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,
示例13: createContext
點讚 2
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,
示例14: renderTo
點讚 2
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,
示例15: unrotate
點讚 2
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,
示例16: paintIcon
點讚 2
import java.awt.Graphics2D; //導入方法依賴的package包/類
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
JRadioButton radioButton = (JRadioButton) c;
ButtonModel bm = radioButton.getModel();
int w = c.getWidth();
int h = c.getHeight();
if (h < 0 || w < 0) {
return;
}
g.translate(x, y);
boolean isSelected = bm.isSelected();
boolean isEnabled = bm.isEnabled();
boolean isPressed = bm.isPressed();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// drawing background section
if (!isEnabled) {
g2.setColor(Colors.RADIOBUTTON_BACKGROUND_DISABLED);
} else {
g2.setColor(Colors.RADIOBUTTON_BACKGROUND);
}
Shape circle = new Ellipse2D.Double(2, 2, 12, 12);
g2.fill(circle);
if (!isEnabled) {
g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
} else {
if (isPressed) {
g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
} else {
g2.setColor(Colors.RADIOBUTTON_BORDER);
}
}
g2.setStroke(RADIO_STROKE);
circle = new Ellipse2D.Double(1, 1, 14, 14);
g2.draw(circle);
// drawing sphere
if (isSelected) {
if (isEnabled) {
g2.setColor(Colors.RADIOBUTTON_CHECKED);
} else {
g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
}
circle = new Ellipse2D.Double(4, 4, 9, 9);
g2.fill(circle);
}
g.translate(-x, -y);
}
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:56,
示例17: main
點讚 2
import java.awt.Graphics2D; //導入方法依賴的package包/類
public static void main(String[] args) {
Locale.setDefault(Locale.US);
// initialize j.u.l Looger:
final Logger log = Logger.getLogger("sun.java2d.marlin");
log.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
Throwable th = record.getThrown();
// detect any Throwable:
if (th != null) {
System.out.println("Test failed:n" + record.getMessage());
th.printStackTrace(System.out);
throw new RuntimeException("Test failed: ", th);
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
});
log.info("TextClipErrorTest: start");
// enable Marlin logging & internal checks:
System.setProperty("sun.java2d.renderer.log", "true");
System.setProperty("sun.java2d.renderer.useLogger", "true");
System.setProperty("sun.java2d.renderer.doChecks", "true");
BufferedImage image = new BufferedImage(256, 256,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.red);
try {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font font = g2d.getFont();
FontRenderContext frc = new FontRenderContext(
new AffineTransform(), true, true);
g2d.setStroke(new BasicStroke(4.0f,
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
final Shape badShape;
if (SERIALIZE) {
final GlyphVector gv1 = font.createGlyphVector(frc, "u00d6");
final Shape textShape = gv1.getOutline();
final AffineTransform at1 = AffineTransform.getTranslateInstance(
-2091202.554154681, 5548.601436981691);
badShape = at1.createTransformedShape(textShape);
serializeShape(badShape);
} else {
badShape = deserializeShape();
}
g2d.draw(badShape);
// Draw anything within bounds and it fails:
g2d.draw(new Line2D.Double(10, 20, 30, 40));
if (SAVE_IMAGE) {
final File file = new File("TextClipErrorTest.png");
System.out.println("Writing file: " + file.getAbsolutePath());
ImageIO.write(image, "PNG", file);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
g2d.dispose();
log.info("TextClipErrorTest: end");
}
}
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:82,
示例18: paintComponent
點讚 2
import java.awt.Graphics2D; //導入方法依賴的package包/類
@Override
public void paintComponent(Graphics g){
Graphics2D g2=(Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(iBorderColor);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 6, 6);
g2.setColor(Color.white);
g2.fillRoundRect(1, 1, getWidth()-2, getHeight()-2, 4, 4);
super.paintComponent(g);
}
開發者ID:davovoid,項目名稱:faitic-checker,代碼行數:19,
示例19: adjustGraphics
點讚 2
import java.awt.Graphics2D; //導入方法依賴的package包/類
private void adjustGraphics(Graphics2D g) {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
開發者ID:limagiran,項目名稱:hearthstone,代碼行數:5,
示例20: render
點讚 1
import java.awt.Graphics2D; //導入方法依賴的package包/類
private void render() {
BufferStrategy buffer = this.getBufferStrategy();
if(buffer == null) {
this.createBufferStrategy(3);
return;
}
Graphics2D g = (Graphics2D) buffer.getDrawGraphics();
g.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.translate(this.getWidth() / 2, this.getHeight() / 2);
camera.translateToCamera(g, this);
camera.translateCameraShake(g);
map.render(g, this);
camera.translateNoCameraShake(g);
camera.translateFromCamera(g);
gameStateManager.render(g, this);
g.dispose();
buffer.show();
}
開發者ID:ProjectK47,項目名稱:Mafia,代碼行數:43,
注:本文中的java.awt.Graphics2D.setRenderingHint方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。
最后
以上就是背后白开水为你收集整理的drawlinetest.java_Java Graphics2D.setRenderingHint方法代碼示例的全部内容,希望文章能够帮你解决drawlinetest.java_Java Graphics2D.setRenderingHint方法代碼示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复