本文整理汇总了Java中java.awt.Graphics.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.dispose方法的具体用法?Java Graphics.dispose怎么用?Java Graphics.dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics
的用法示例。
在下文中一共展示了Graphics.dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintIcon
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintIcon(java.awt.Component c, Graphics g, int x, int y) {
// draw tool icon
Graphics gIcon = g.create();
ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, gIcon);
comp.getFactory().paintIcon(context, x, y, comp.getAttributeSet());
gIcon.dispose();
if (triangleState != TRIANGLE_NONE) {
int[] xp;
int[] yp;
if (triangleState == TRIANGLE_CLOSED) {
xp = new int[] { x + 13, x + 13, x + 17 };
yp = new int[] { y + 11, y + 19, y + 15 };
} else {
xp = new int[] { x + 11, x + 19, x + 15 };
yp = new int[] { y + 13, y + 13, y + 17 };
}
g.setColor(Color.LIGHT_GRAY);
g.fillPolygon(xp, yp, 3);
g.setColor(Color.DARK_GRAY);
g.drawPolygon(xp, yp, 3);
}
}
示例2: flip
import java.awt.Graphics; //导入方法依赖的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();
}
}
}
示例3: rasterize
import java.awt.Graphics; //导入方法依赖的package包/类
/**
* rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
*/
public BufferedImage rasterize(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {
// create the buffered image of the size of the Rectangle
BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
GeometryFactory gf = new GeometryFactory();
// define the clipping region in full scale
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords));
Graphics g2d = image.getGraphics();
g2d.setColor(Color.white);
for (Geometry p : maskGeometries) {
/*if(p instanceof MultiPolygon){
p=p.getBoundary();
}*/
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];//build array for x coordinates
int[] yPoints = new int[p.getNumPoints()];//build array for y coordinates
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) ((c.x + offsetX ) * scalingFactor);
yPoints[i] = (int) ((c.y + offsetY ) * scalingFactor);
i++;
}
g2d.fillPolygon(xPoints, yPoints, i);
}
}
g2d.dispose();
return image;
}
示例4: paintSubcircuit
import java.awt.Graphics; //导入方法依赖的package包/类
public void paintSubcircuit(Graphics g, Direction facing) {
Direction defaultFacing = getFacing();
double rotate = 0.0;
if (facing != defaultFacing && g instanceof Graphics2D) {
rotate = defaultFacing.toRadians() - facing.toRadians();
((Graphics2D) g).rotate(rotate);
}
Location offset = findAnchorLocation();
g.translate(-offset.getX(), -offset.getY());
for (CanvasObject shape : getObjectsFromBottom()) {
if (!(shape instanceof AppearanceElement)) {
Graphics dup = g.create();
shape.paint(dup, null);
dup.dispose();
}
}
g.translate(offset.getX(), offset.getY());
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
}
示例5: getPreferredSize
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize(PaintContext context)
{
Dimension size = null;
// Get a shared buffer to use for measuring
BufferedImage buffer = _createOffscreenBuffer(context, 1, 1);
if (buffer != null)
{
Graphics g = _getInitializedGraphics(context, buffer);
size = super.getPreferredSize(new ProxyContext(context, g));
// Clean up
g.dispose();
buffer.flush();
}
else
{
// If we didn't get a buffer, just paint the contents directly
size = super.getPreferredSize(context);
}
return size;
}
示例6: createMenuIcon
import java.awt.Graphics; //导入方法依赖的package包/类
private static Icon createMenuIcon(Icon icon, Component decorator) {
int h = menuIconSize();
int w = UIUtils.isAquaLookAndFeel() ? h + 4 : h;
BufferedImage i = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = i.getGraphics();
if (decorator != null) {
decorator.setSize(w, h);
decorator.paint(g);
}
icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2);
g.dispose();
return new ImageIcon(i);
}
示例7: erase
import java.awt.Graphics; //导入方法依赖的package包/类
public void erase() {
Graphics g = getGraphics();
if (g != null) {
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
g.dispose();
}
}
示例8: insertImage
import java.awt.Graphics; //导入方法依赖的package包/类
private static void insertImage(BufferedImage source, String imgPath,
boolean needCompress) throws Exception {
File file = new File(imgPath);
if (!file.exists()) {
System.err.println(""+imgPath+" 该文件不存在!");
return;
}
Image src = ImageIO.read(new File(imgPath));
int width = src.getWidth(null);
int height = src.getHeight(null);
if (needCompress) {// 压缩LOGO
if (width > WIDTH) {
width = WIDTH;
}
if (height > HEIGHT) {
height = HEIGHT;
}
Image image = src.getScaledInstance(width, height,
Image.SCALE_SMOOTH);
BufferedImage tag = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(image, 0, 0, null); // 绘制缩小后的图
g.dispose();
src = image;
}
// 插入LOGO
Graphics2D graph = source.createGraphics();
int x = (QRCODE_SIZE - width) / 2;
int y = (QRCODE_SIZE - height) / 2;
graph.drawImage(src, x, y, width, height, null);
Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
graph.setStroke(new BasicStroke(3f));
graph.draw(shape);
graph.dispose();
}
示例9: draw
import java.awt.Graphics; //导入方法依赖的package包/类
public void draw() {
requestFocus();
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = currentFrame.getGraphics();
GameCanvas.g = g;
g.setColor(Color.GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
if (Game.paused) {
if (!isBlurred) {
if (StateHandler.pausedGame != null) {
StateHandler.pausedGame.render(g);
blurred = Tools.blur(currentFrame);
isBlurred = true;
}
}
} else isBlurred = false;
StateHandler.render(g);
bs.getDrawGraphics().drawImage(currentFrame, 0, 0, StateHandler.WIDTH, StateHandler.HEIGHT, null);
g.dispose();
bs.show();
}
示例10: getImage
import java.awt.Graphics; //导入方法依赖的package包/类
static BufferedImage getImage(JComponent component, int scale, int width, int height) {
final BufferedImage image = new BufferedImage(
scale * width, scale * height, BufferedImage.TYPE_INT_ARGB);
final Graphics g = image.getGraphics();
((Graphics2D) g).scale(scale, scale);
component.paint(g);
g.dispose();
return image;
}
示例11: paint
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, Selection selection) {
Set<CanvasObject> suppressed = selection.getDrawsSuppressed();
for (CanvasObject shape : getObjectsFromBottom()) {
Graphics dup = g.create();
if (suppressed.contains(shape)) {
selection.drawSuppressed(dup, shape);
} else {
shape.paint(dup, null);
}
dup.dispose();
}
}
示例12: TestSurfaceData
import java.awt.Graphics; //导入方法依赖的package包/类
public TestSurfaceData(int width, int height, double scale) {
super(StateTrackable.State.DYNAMIC, SurfaceType.Custom, ColorModel.getRGBdefault());
this.scale = scale;
gc = new TestGraphicsConfig(scale);
this.width = (int) Math.ceil(scale * width);
this.height = (int) Math.ceil(scale * height);
buffImage = new BufferedImage(this.width, this.height,
BufferedImage.TYPE_INT_RGB);
Graphics imageGraphics = buffImage.createGraphics();
imageGraphics.setColor(BACKGROUND_COLOR);
imageGraphics.fillRect(0, 0, this.width, this.height);
imageGraphics.dispose();
}
示例13: paintIcon
import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintIcon(Component destination, Graphics g) {
// draw halo
if (tool == haloedTool && AppPreferences.ATTRIBUTE_HALO.getBoolean()) {
g.setColor(Canvas.HALO_COLOR);
g.fillRect(1, 1, 22, 22);
}
// draw tool icon
g.setColor(Color.BLACK);
Graphics g_copy = g.create();
ComponentDrawContext c = new ComponentDrawContext(destination, null, null, g, g_copy);
tool.paintIcon(c, 2, 2);
g_copy.dispose();
}
示例14: TextureWatchFX
import java.awt.Graphics; //导入方法依赖的package包/类
public TextureWatchFX(Minecraft minecraft)
{
super(Item.pocketSundial.getIconFromDamage(0));
isCustom = true;
mc = minecraft;
res = (Integer)mc.renderEngine.textureSizeIdMap.get(mc.renderEngine.getTexture("/gui/items.png"))/16;
watchIconImageData = new int[res*res];
dialImageData = new int[res*res];
imageData = new byte[res*res*4];
tileImage = 1;
try
{
BufferedImage bufferedimage = ImageIO.read(mc.texturePackList.selectedTexturePack.getResourceAsStream("/gui/items.png"));
int i = (iconIndex % 16) * res;
int j = (iconIndex / 16) * res;
bufferedimage.getRGB(i, j, res, res, watchIconImageData, 0, res);
bufferedimage = ImageIO.read(mc.texturePackList.selectedTexturePack.getResourceAsStream("/misc/dial.png"));
if(bufferedimage.getWidth() != res)
{
BufferedImage tmp = new BufferedImage(res,res,BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = tmp.createGraphics();
g.drawImage(bufferedimage, 0, 0, res,res, null);
g.dispose();
bufferedimage = tmp;
}
bufferedimage.getRGB(0, 0, res, res, dialImageData, 0, res);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
}
示例15: render
import java.awt.Graphics; //导入方法依赖的package包/类
public void render() {
ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
BufferCapabilities bufCap =
new BufferCapabilities(imgFrontBufCap,
imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
try {
createBufferStrategy(2, bufCap);
} catch (AWTException ex) {
createBufferStrategy(2);
}
BufferStrategy bs = getBufferStrategy();
do {
Graphics g = bs.getDrawGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.red);
g.drawString("Rendering test", 20, 20);
g.drawImage(bi, 50, 50, null);
g.dispose();
bs.show();
} while (bs.contentsLost()||bs.contentsRestored());
}