本文整理汇总了Java中java.awt.Graphics2D.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.dispose方法的具体用法?Java Graphics2D.dispose怎么用?Java Graphics2D.dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics g, Map map) {
if (drawGhost) {
final Point p = map.componentCoordinates(getGhostPosition());
final Graphics2D g2d = (Graphics2D) g.create();
g2d.transform(
AffineTransform.getRotateInstance(-PI_180 * tempAngle,
p.x + centerX(),
p.y + centerY()));
g2d.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
piece.draw(g2d, p.x, p.y, map.getView(), map.getZoom());
g2d.dispose();
}
}
示例2: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
super.paintComponent(g2d);
int gridSize = 10;
int majorGridSize = 100;
g2d.setColor(new Color(0x484848));
for (int i = 0; i < Math.max(getWidth(), getHeight()); i += gridSize) {
if (i < getWidth()) {
g2d.drawLine(i, 0, i, getHeight());
}
if (i < getHeight()) {
g2d.drawLine(0, i, getWidth(), i);
}
}
g2d.setColor(new Color(0x585858));
for (int i = 0; i < Math.max(getWidth(), getHeight()); i += majorGridSize) {
if (i < getWidth()) {
g2d.drawLine(i, 0, i, getHeight());
}
if (i < getHeight()) {
g2d.drawLine(0, i, getWidth(), i);
}
}
g2d.dispose();
}
示例3: createTestImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected BufferedImage createTestImage(int numColors) {
IndexColorModel icm = createTestICM(numColors);
int w = numColors * 10;
int h = 20;
BufferedImage img = new BufferedImage(w, h,
BufferedImage.TYPE_BYTE_INDEXED, icm);
Graphics2D g = img.createGraphics();
for (int i = 0; i < numColors; i++) {
int rgb = icm.getRGB(i);
//System.out.printf("pixel %d, rgb %x\n", i, rgb);
g.setColor(new Color(rgb));
g.fillRect(i * 10, 0, w - i * 10, h);
}
g.dispose();
return img;
}
示例4: drawBoxes
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draw symbols boxes and None symbols locations on control image.
*
* @param controlPath target path for control image
* @throws java.io.IOException in case of IO problem
*/
public void drawBoxes (Path controlPath)
throws IOException
{
BufferedImage ctrl = new BufferedImage(
initialImg.getWidth(),
initialImg.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = ctrl.createGraphics();
g.drawImage(initialImg, null, null);
drawSymbols(annotations.getSymbols(), g);
g.dispose();
Files.createDirectories(controlPath.getParent());
ImageIO.write(ctrl, OUTPUT_IMAGES_FORMAT, controlPath.toFile());
}
示例5: redimensionaImg
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Redimensiona a imagem do caminho passado por parâmetro
*
* @param image imagem
* @param razao proporção do redimensionamento
* @return retorna a imagem redimensionada
*/
public static ImageIcon redimensionaImg(Image image, double razao) {
double new_w, new_h;
ImageIcon img = new ImageIcon(image);
new_w = img.getIconWidth();
new_h = img.getIconHeight();
new_w *= razao;
new_h *= razao;
BufferedImage new_img = new BufferedImage((int) new_w, (int) new_h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = new_img.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g.drawImage(image, 0, 0, (int) new_w, (int) new_h, null);
g.dispose();
return new ImageIcon(new_img);
}
示例6: flip
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer,
final int x1, final int y1, final int x2, final int y2,
final BufferCapabilities.FlipContents flipAction) {
final Graphics g = peer.getGraphics();
try {
g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
} finally {
g.dispose();
}
if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
final Graphics2D bg = (Graphics2D) backBuffer.getGraphics();
try {
bg.setBackground(peer.getBackground());
bg.clearRect(0, 0, backBuffer.getWidth(null),
backBuffer.getHeight(null));
} finally {
bg.dispose();
}
}
}
示例7: flipHoriz
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage flipHoriz(BufferedImage image) {
BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D gg = newImage.createGraphics();
gg.drawImage(image, image.getHeight(), 0, -image.getWidth(), image.getHeight(), null);
gg.dispose();
return newImage;
}
示例8: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(Color.WHITE);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
g2.fillRect(0, 0, getWidth(), getHeight());
g2.dispose();
}
示例9: 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();
}
示例10: main
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(final String[] args)
throws NoninvertibleTransformException {
final BufferedImage bi = new BufferedImage(300, 300,
BufferedImage.TYPE_INT_RGB);
final Graphics2D g = (Graphics2D) bi.getGraphics();
test(g);
g.translate(2.0, 2.0);
test(g);
g.translate(-4.0, -4.0);
test(g);
g.scale(2.0, 2.0);
test(g);
g.scale(-4.0, -4.0);
test(g);
g.rotate(Math.toRadians(90));
test(g);
g.rotate(Math.toRadians(90));
test(g);
g.rotate(Math.toRadians(90));
test(g);
g.rotate(Math.toRadians(90));
test(g);
g.dispose();
if (!status) {
throw new RuntimeException("Test failed");
}
}
示例11: createTestFile
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void createTestFile() {
int w = 1280;
int h = 1024;
BufferedImage img = new
BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
Color[] colors = { Color.red, Color.green, Color.blue };
float[] dist = {0.0f, 0.5f, 1.0f };
Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
RadialGradientPaint p =
new RadialGradientPaint(center, 0.5f * w, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, w, h);
g.dispose();
try {
System.out.println("Create test image " + file.getAbsolutePath());
boolean b = ImageIO.write(img, "JPEG", file);
if (!b) {
throw new RuntimeException("Failed to create test image.");
}
} catch (IOException e) {
throw new RuntimeException("Test failed", e);
}
}
示例12: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setColor(Color.BLACK);
/* Using the assistant now instead of text ontop of the glasspane.
* josh: I need to delete all of the previous code related to the showMenubarWarning boolean
if(showMenubarWarning) {
g2.drawString("You cannot add a menu component to a form without a menubar.", 5, getHeight()-30);
}*/
g2.dispose();
}
示例13: getGradientColor
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static Color getGradientColor(int w, int h, Color c1, Color c2) {
GradientPaint gradient = new GradientPaint(0, 0, c1, 0, h, c2,
true);
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
g.setPaint(gradient);
g.fillRect(0, 0, w, h);
g.dispose();
return new Color(img.getRGB(w / 2, h / 2));
}
示例14: getSourceGold
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage getSourceGold(GraphicsConfiguration gc,
int size) {
final BufferedImage bi = gc.createCompatibleImage(size, size);
Graphics2D g2d = bi.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
return bi;
}
示例15: step1
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Draws standard JMenuBar.
*/
private BufferedImage step1(final JMenuBar menubar) {
final BufferedImage bi1 = new BufferedImage(W, H, TYPE_INT_ARGB_PRE);
final Graphics2D g2d = bi1.createGraphics();
g2d.scale(2, 2);
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, W, H);
menubar.paintAll(g2d);
g2d.dispose();
return bi1;
}