本文整理汇总了Java中java.awt.Graphics2D.setRenderingHints方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setRenderingHints方法的具体用法?Java Graphics2D.setRenderingHints怎么用?Java Graphics2D.setRenderingHints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.setRenderingHints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Transforms source image using transform specified at the constructor.
* The resulting transformed image is stored in the destination image if one
* is provided; otherwise a new BufferedImage is created and returned.
*
* @param src source image
* @param dst destination image
* @throws IllegalArgumentException if the source and destination image are
* the same
* @return transformed source image.
*/
public final BufferedImage filter (BufferedImage src, BufferedImage dst)
{
if (dst == src)
throw new IllegalArgumentException("src image cannot be the same as "
+ "the dst image");
// If the destination image is null, then use a compatible BufferedImage
if (dst == null)
dst = createCompatibleDestImage(src, null);
Graphics2D gr = dst.createGraphics();
gr.setRenderingHints(hints);
gr.drawImage(src, transform, null);
return dst;
}
示例2: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public @Override void paint(Graphics g) {
Object value = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
Map renderingHints = (value instanceof Map) ? (java.util.Map)value : null;
if (renderingHints != null && g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g;
RenderingHints oldHints = g2d.getRenderingHints();
g2d.setRenderingHints(renderingHints);
try {
super.paint(g2d);
} finally {
g2d.setRenderingHints(oldHints);
}
} else {
super.paint(g);
}
}
示例3: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHints(rh);
Dimension size = getSize();
if (initialize) {
reset(size.width, size.height);
initialize = false;
}
this.step(size.width, size.height);
render(size.width, size.height, g2);
}
示例4: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public
@Override
void paint(Graphics g) {
// Antialiasing if necessary
Object value = (Map) (Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
Map renderingHints = (value instanceof Map) ? (java.util.Map) value : null;
if (renderingHints != null && g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g;
RenderingHints oldHints = g2d.getRenderingHints();
g2d.setRenderingHints(renderingHints);
try {
super.paint(g2d);
} finally {
g2d.setRenderingHints(oldHints);
}
} else {
super.paint(g);
}
}
示例5: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public @Override void paint(Graphics g) {
Object value = Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"); //NOI18N
Map renderingHints = (value instanceof Map) ? (java.util.Map)value : null;
if (renderingHints != null && g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g;
RenderingHints oldHints = g2d.getRenderingHints();
g2d.setRenderingHints(renderingHints);
try {
super.paint(g2d);
} finally {
g2d.setRenderingHints(oldHints);
}
} else {
super.paint(g);
}
}
示例6: cacheAnnotationImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Creates an image of the given annotation and caches it with the specified cache id.
*
* @param anno
* the annotation to cache
* @param cacheId
* the cache id for the given annotation
* @return the cached image
*/
private Image cacheAnnotationImage(final WorkflowAnnotation anno, final int cacheId) {
Rectangle2D loc = anno.getLocation();
// paint each annotation with the same JEditorPane
Dimension size = new Dimension((int) loc.getWidth(), (int) loc.getHeight());
pane.setSize(size);
pane.setText(AnnotationDrawUtils.createStyledCommentString(anno));
pane.setCaretPosition(0);
// draw annotation area to image and then to graphics
// otherwise heavyweight JEdiorPane draws over everything and outside of panel
BufferedImage img = new BufferedImage((int) loc.getWidth(), (int) loc.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D gImg = img.createGraphics();
gImg.setRenderingHints(ProcessDrawer.HI_QUALITY_HINTS);
// without this, the text is pixelated on half opaque backgrounds
gImg.setComposite(AlphaComposite.SrcOver);
// paint JEditorPane to image
pane.paint(gImg);
displayCache.put(anno.getId(), new SoftReference<Image>(img));
cachedID.put(anno.getId(), cacheId);
return img;
}
示例7: getResizedIcon
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected Icon getResizedIcon(Icon originalIcon) {
if(originalIcon == null) {
return null;
} else {
int width = originalIcon.getIconWidth();
int height = originalIcon.getIconHeight();
if(width != 48) {
double scale = 48.0D / (double)width;
BufferedImage bi = new BufferedImage((int)(scale * (double)width), (int)(scale * (double)height), 2);
Graphics2D g = bi.createGraphics();
g.setRenderingHints(HI_QUALITY_HINTS);
g.scale(scale, scale);
originalIcon.paintIcon((Component)null, g, 0, 0);
g.dispose();
return new ImageIcon(bi);
} else {
return originalIcon;
}
}
}
示例8: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
RenderingHints rh = new RenderingHints(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHints(rh);
g.setColor(BloxsColors.$BACKGROUND);
g.fillRect(0, 0, getWidth(), getHeight());
for (int i = 0; i < elements.size(); i++) {
Element get = elements.get(i);
get.draw((Graphics2D) g);
}
}
示例9: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics g) {
if (selectedValues.isEmpty()) return;
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHints(chart.getRenderingHints());
Iterator<Point> it = selectedValues.iterator();
boolean linePainted = false;
while (it.hasNext()) {
Point p = it.next();
if (!linePainted) {
g2.setPaint(evenPerfPaint);
g2.setStroke(evenPerfStroke);
g2.drawLine(p.x, 0, p.x, getHeight());
g2.setPaint(oddPerfPaint);
g2.setStroke(oddPerfStroke);
g2.drawLine(p.x, 0, p.x, getHeight());
g2.setPaint(markPaint);
g2.setStroke(markStroke);
linePainted = true;
}
g2.fillOval(p.x - selectionExtent + 1, p.y - selectionExtent + 1,
selectionExtent * 2 - 1, selectionExtent * 2 - 1);
}
}
示例10: paintBorder
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHints(ProcessDrawer.HI_QUALITY_HINTS);
g2d.setStroke(new BasicStroke(2f));
// clear edges, otherwise they will be in the color of the component background
if (drawRoundFrame && !c.getBackground().equals(c.getParent().getBackground())) {
Shape frame = new Rectangle2D.Float(x + 2, y + 2, width - 4, height - 4);
g2d.setPaint(c.getParent().getBackground());
g2d.draw(frame);
}
g2d.setPaint(paint);
g2d.setFont(new Font("Dialog", Font.BOLD, 21));
if (drawRoundFrame) {
Shape roundFrame = new RoundRectangle2D.Float(x + 2, y + 2, width - 4, height - 4, 10, 10);
g2d.draw(roundFrame);
}
if (number > 0) {
Shape circle = new Ellipse2D.Float(20, 20, 34, 34);
g2d.fill(circle);
g2d.setPaint(Color.WHITE);
g2d.drawString(String.valueOf(number), 29, 44);
}
if (key != null) {
g2d.setPaint(paint);
g2d.drawString(key, 60, 44);
}
g2d.dispose();
}
示例11: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
double scaleX = (double) getWidth() / (double) processRenderer.getWidth();
double scaleY = (double) getHeight() / (double) processRenderer.getHeight();
scale = Math.min(scaleX, scaleY);
double scaledW = processRenderer.getWidth() * scale;
double scaledH = processRenderer.getHeight() * scale;
Graphics2D g = (Graphics2D) graphics.create();
g.translate((getWidth() - scaledW) / 2d, (getHeight() - scaledH) / 2d);
g.scale(scale, scale);
g.setRenderingHints(ProcessDrawer.LOW_QUALITY_HINTS);
processRenderer.getOverviewPanelDrawer().draw(g, true);
g.setStroke(new BasicStroke((int) (1d / scale)));
Rectangle visibleRect = processRenderer.getVisibleRect();
Rectangle drawRect = new Rectangle((int) visibleRect.getX(), (int) visibleRect.getY(),
(int) visibleRect.getWidth() - 1, (int) visibleRect.getHeight() - 1);
g.setColor(FILL_COLOR);
g.fill(drawRect);
g.setColor(DRAW_COLOR);
g.draw(drawRect);
g.dispose();
}
示例12: render
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public BufferedImage render(final BufferedImage baseImage) {
int width = baseImage.getWidth();
int height = baseImage.getHeight();
// create an opaque image
RenderingHints hints = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
hints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY));
hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY));
hints.add(new RenderingHints(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY));
BufferedImage imageWithBackground = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graph = (Graphics2D) imageWithBackground.getGraphics();
graph.setRenderingHints(hints);
graph.setPaint(new GradientPaint(0, 0, colorFrom, width, height, colorTo));
graph.fill(new Rectangle2D.Double(0, 0, width, height));
graph.drawImage(baseImage, 0, 0, null);
graph.dispose();
return imageWithBackground;
}
示例13: apply
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void apply(Graphics2D g)
{
g.setTransform(transform);
g.setPaint(paint);
g.setStroke(stroke);
g.setFont(font);
g.setComposite(composite);
g.setBackground(bgrnd);
g.setClip(shape);
g.setRenderingHints(hints);
}
示例14: copyimage
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Copy a source image to a destination image, respecting their colorspaces
* and performing colorspace conversions if necessary.
*
* @param src The source image.
* @param dst The destination image.
*/
private void copyimage(BufferedImage src, BufferedImage dst)
{
// This is done using Graphics2D in order to respect the rendering hints.
Graphics2D gg = dst.createGraphics();
// If no hints are set there is no need to call
// setRenderingHints on the Graphics2D object.
if (hints != null)
gg.setRenderingHints(hints);
gg.drawImage(src, 0, 0, null);
gg.dispose();
}
示例15: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
*
*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Draws the background
paintBackground(g);
// Creates or destroys the triple buffer as needed
if (tripleBuffered) {
checkTripleBuffer();
} else if (tripleBuffer != null) {
destroyTripleBuffer();
}
// Paints the buffer in the canvas onto the dirty region
if (tripleBuffer != null) {
mxUtils.drawImageClip(g, tripleBuffer, this);
}
// Paints the graph directly onto the graphics
else {
Graphics2D g2 = (Graphics2D) g;
RenderingHints tmp = g2.getRenderingHints();
// Sets the graphics in the canvas
try {
mxUtils.setAntiAlias(g2, antiAlias, textAntiAlias);
drawGraph(g2, true);
} finally {
// Restores the graphics state
g2.setRenderingHints(tmp);
}
}
eventSource.fireEvent(new mxEventObject(mxEvent.PAINT, "g", g));
}