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


Java Image.getGraphics方法代码示例

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


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

示例1: createCompImage

import java.awt.Image; //导入方法依赖的package包/类
private Image createCompImage(Component comp, Dimension targetSize) {
    // component won't paint if not showing anyway, so don't create
    // empty image but honestly return null 
    if (!comp.isShowing()) {
        return null;
    }
    
    Image image = comp.createImage(comp.getWidth(), comp.getHeight());
    
    /*BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            createCompatibleImage(comp.getWidth(), comp.getHeight());*/
    //BufferedImage image = new BufferedImage (targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB);
    
    Graphics2D gr2d = (Graphics2D)image.getGraphics();
    
    comp.paint(gr2d);
    
    gr2d.dispose();
    
    return image;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ScaleFx.java

示例2: setComponent

import java.awt.Image; //导入方法依赖的package包/类
/**
 * Set the cell renderer we will proxy.
 */
public void setComponent (Component jc, JComponent owner) {
    Dimension dd = jc.getPreferredSize();
    Rectangle currentScreenBounds = Utilities.getUsableScreenBounds();
    // get some reasonable limit for the width
    int width = Math.min(dd.width, 2 * currentScreenBounds.width);
    int height = Math.min(dd.height + 2, 2 * currentScreenBounds.height);
    Image nue = !Utilities.isMac() ? owner.createVolatileImage(width, height) :
                new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = nue.getGraphics();
    g.setColor (bg);
    g.fillRect (0, 0, width, dd.height + 2);
    if( jc instanceof Container && !jc.isValid() ) {
        //#214739
        jc.setSize( width, dd.height );
        jc.doLayout();
    }
    SwingUtilities.paintComponent(g, jc, this, 0, 0, width, dd.height + 2);
    g.dispose();
    setImage (nue);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ViewTooltips.java

示例3: modifyTest

import java.awt.Image; //导入方法依赖的package包/类
public void modifyTest(TestEnvironment env) {
    int size = env.getIntValue(sizeList);
    Image src = tsit.getImage(env, size, size);
    Graphics g = src.getGraphics();
    if (hasGraphics2D) {
        ((Graphics2D) g).setComposite(AlphaComposite.Src);
    }
    if (size == 1) {
        g.setColor(colorsets[transparency][4]);
        g.fillRect(0, 0, 1, 1);
    } else {
        int mid = size/2;
        g.setColor(colorsets[transparency][0]);
        g.fillRect(0, 0, mid, mid);
        g.setColor(colorsets[transparency][1]);
        g.fillRect(mid, 0, size-mid, mid);
        g.setColor(colorsets[transparency][2]);
        g.fillRect(0, mid, mid, size-mid);
        g.setColor(colorsets[transparency][3]);
        g.fillRect(mid, mid, size-mid, size-mid);
    }
    g.dispose();
    env.setSrcImage(src);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:ImageTests.java

示例4: flip

import java.awt.Image; //导入方法依赖的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();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:CGLGraphicsConfig.java

示例5: updateWindow

import java.awt.Image; //导入方法依赖的package包/类
/**
 * Updates the window associated with the painter.
 *
 * @param repaint indicates if the window should be completely repainted
 * to the back buffer using {@link java.awt.Window#paintAll} before update.
 */
public void updateWindow(boolean repaint) {
    boolean done = false;
    Image bb = getBackBuffer(repaint);
    while (!done) {
        if (repaint) {
            Graphics2D g = (Graphics2D)bb.getGraphics();
            try {
                window.paintAll(g);
            } finally {
                g.dispose();
            }
        }

        done = update(bb);
        if (!done) {
            repaint = true;
            bb = getBackBuffer(true);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:TranslucentWindowPainter.java

示例6: render

import java.awt.Image; //导入方法依赖的package包/类
private void render(Image im, int type, String s) {
    Graphics2D g2d = (Graphics2D) im.getGraphics();
    clear(g2d, type, im.getWidth(null), im.getHeight(null));
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    Font f = new Font("Dialog", Font.BOLD, 40);// g2d.getFont().deriveFont(32.0f);
    g2d.setColor(Color.white);
    g2d.setFont(g2d.getFont().deriveFont(36.0f));
    g2d.drawString(s, 10, im.getHeight(null) / 2);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:NonOpaqueDestLCDAATest.java

示例7: paint

import java.awt.Image; //导入方法依赖的package包/类
public void paint(Component c, Graphics g, int x, int y, int w, int h, Object[] args) {
	if (w <= 0 || h <= 0) {
		return;
	}
	Object key = getClass();
	GraphicsConfiguration config = c.getGraphicsConfiguration();
	Cache cache = getCache(key);
	Image image = cache.getImage(key, config, w, h, args);
	int attempts = 0;
	do {
		boolean draw = false;
		if (image instanceof VolatileImage) {
			switch (((VolatileImage) image).validate(config)) {
				case VolatileImage.IMAGE_INCOMPATIBLE:
					((VolatileImage) image).flush();
					image = null;
					break;
				case VolatileImage.IMAGE_RESTORED:
					draw = true;
					break;
			}
		}
		if (image == null) {
			image = createImage(c, w, h, config);
			cache.setImage(key, config, w, h, args, image);
			draw = true;
		}
		if (draw) {
			Graphics g2 = image.getGraphics();
			paintToImage(c, g2, w, h, args);
			g2.dispose();
		}

		paintImage(c, g, x, y, w, h, image, args);
	} while (image instanceof VolatileImage && ((VolatileImage) image).contentsLost() && ++attempts < 3);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:37,代码来源:AbstractCachedPainter.java

示例8: fill

import java.awt.Image; //导入方法依赖的package包/类
private static void fill(Image image, Color color) {
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setColor(color);
    g2d.setComposite(AlphaComposite.Src);
    g2d.fillRect(0, 0, S, S);
    g2d.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:BitmaskVolatileImage.java

示例9: draw

import java.awt.Image; //导入方法依赖的package包/类
private static void draw(final BufferedImage from,final Image to) {
    final Graphics2D g2d = (Graphics2D) to.getGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(Color.ORANGE);
    g2d.fillRect(0, 0, to.getWidth(null), to.getHeight(null));
    g2d.rotate(Math.toRadians(45));
    g2d.clip(new Rectangle(41, 42, 43, 44));
    g2d.drawImage(from, 50, 50, Color.blue, null);
    g2d.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:IncorrectUnmanagedImageRotatedClip.java

示例10: draw

import java.awt.Image; //导入方法依赖的package包/类
private static void draw(Shape clip, Shape shape, Image from, Image to) {
    Graphics2D g2d = (Graphics2D) to.getGraphics();
    g2d.setXORMode(Color.BLACK);
    g2d.setClip(clip);
    Rectangle toBounds = shape.getBounds();
    g2d.drawImage(from, toBounds.x, toBounds.y, toBounds.width,
                  toBounds.height, null);
    g2d.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:IncorrectClipXorModeSW2Surface.java

示例11: cutImage

import java.awt.Image; //导入方法依赖的package包/类
private static SpriteSheet cutImage(GraphicsConfiguration gc, String imageName, int xSize, int ySize) throws IOException 
{
	xSize*=GlobalOptions.resolution_factor;
	ySize*=GlobalOptions.resolution_factor;
			
	Image source = getImage(gc, imageName);		
			
	Image[][] cutsource = new Image[source.getWidth(null) / xSize][source.getHeight(null) / ySize];		
	
	for (int x = 0; x < source.getWidth(null) / xSize; x++) 
	{
		for (int y = 0; y < source.getHeight(null) / ySize; y++) 
		{
			Image image = gc.createCompatibleImage(xSize, ySize, Transparency.TRANSLUCENT);
			Graphics2D g = (Graphics2D) image.getGraphics();
							
			//g.setComposite(AlphaComposite.Src);
			
			//ENABLE PARTIAL TRANSPARENCY
			AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC);
	        g.setComposite(ac);						
			
			g.drawImage(source, -x * xSize, -y * ySize, null);
			g.dispose();
			
			cutsource[x][y] = image;
		}
	}		
	
	System.out.println(imageName);
	SpriteSheet ret = new SpriteSheet(xSize, ySize, source.getWidth(null) / xSize, source.getHeight(null) / ySize, cutsource);
	
	return ret;
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:35,代码来源:Art.java

示例12: initImage

import java.awt.Image; //导入方法依赖的package包/类
static void initImage(GraphicsConfiguration gc, Image image) {
    Graphics g = image.getGraphics();
    g.setColor(Color.RED);
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    g.fillRect(0, 0, w, h);
    g.dispose();

    // need to 'accelerate' the image
    if (dstImage == null) {
        dstImage =
            gc.createCompatibleVolatileImage(TESTW, TESTH,
                                             Transparency.OPAQUE);
    }
    dstImage.validate(gc);
    g = dstImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:SourceClippingBlitTest.java

示例13: fill

import java.awt.Image; //导入方法依赖的package包/类
private static void fill(final Image image) {
    final Graphics2D graphics = (Graphics2D) image.getGraphics();
    graphics.setComposite(AlphaComposite.Src);
    for (int i = 0; i < image.getHeight(null); ++i) {
        graphics.setColor(new Color(i, 0, 0));
        graphics.fillRect(0, i, image.getWidth(null), 1);
    }
    graphics.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:IncorrectUnmanagedImageSourceOffset.java

示例14: fill

import java.awt.Image; //导入方法依赖的package包/类
private static void fill(Image image) {
    Graphics2D graphics = (Graphics2D) image.getGraphics();
    graphics.setComposite(AlphaComposite.Src);
    for (int i = 0; i < image.getHeight(null); ++i) {
        graphics.setColor(new Color(i, 0, 0));
        graphics.fillRect(0, i, image.getWidth(null), 1);
    }
    graphics.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:IncorrectSourceOffset.java

示例15: clearImage

import java.awt.Image; //导入方法依赖的package包/类
private static final Image clearImage(Image bb) {
    Graphics2D g = (Graphics2D)bb.getGraphics();
    int w = bb.getWidth(null);
    int h = bb.getHeight(null);

    g.setComposite(AlphaComposite.Src);
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, w, h);

    return bb;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TranslucentWindowPainter.java


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