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


Java BufferedImage.getGraphics方法代码示例

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


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

示例1: generateImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static BufferedImage generateImage(int scale, Color c) {
    int x = SZ * scale;
    BufferedImage img = new BufferedImage(x, x, BufferedImage.TYPE_INT_RGB);
    Graphics g = img.getGraphics();
    try {
        if (g != null) {
            g.setColor(c);
            g.fillRect(0, 0, x, x);
            g.setColor(Color.GREEN);
            g.drawRect(0, 0, x-1, x-1);
        }
    } finally {
        g.dispose();
    }
    return img;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IconTest.java

示例2: ImageGenerator

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public ImageGenerator(int _width, int _height, Color bgColor)
{
      width = _width;
      height = _height;
      bi = new BufferedImage(
          width,
          height,
          BufferedImage.TYPE_INT_ARGB);
      Graphics gr = bi.getGraphics();
      if(null==bgColor){
          bgColor = Color.WHITE;
      }
      gr.setColor(bgColor);
      gr.fillRect(0, 0, width, height);
      paint(gr);
      gr.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ImageGenerator.java

示例3: runTest

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    ImageOpTests.Context ictx = (ImageOpTests.Context)ctx;
    BufferedImageOp op = ictx.bufImgOp;
    BufferedImage src = ictx.bufSrc;
    BufferedImage dst = ictx.bufDst;
    if (ictx.touchSrc) {
        Graphics gSrc = src.getGraphics();
        do {
            gSrc.fillRect(0, 0, 1, 1);
            op.filter(src, dst);
        } while (--numReps > 0);
    } else {
        do {
            op.filter(src, dst);
        } while (--numReps > 0);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ImageTests.java

示例4: DisplayChangeVITest

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:DisplayChangeVITest.java

示例5: setBackground

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Sets the background attribute of the YassSongInfo object
 *
 * @param im The new background value
 */
public void setBackground(Image im) {
    bgString = null;

    origbg = new BufferedImage(im.getWidth(null), im.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics g = origbg.getGraphics();
    g.drawImage(im, 0, 0, null);
    g.dispose();

    imgbg = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = imgbg.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    g2d.drawImage(origbg, 0, 0, 800, 600, null);
    g2d.dispose();

    setProperty("bg-filename", "");
    setProperty("bg-filesize", "");
    setProperty("bg-width", origbg == null ? "" : origbg.getWidth() + "");
    setProperty("bg-height", origbg == null ? "" : origbg.getHeight() + "");

    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:31,代码来源:YassSongInfo.java

示例6: makeWordImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 *
 * @param s
 * @param flag 0 : white | 1 : yellow | 2 : gray
 * @return
 */
public static BufferedImage makeWordImage(String s, int flag) {
	BufferedImage ret = new BufferedImage(s.length() * 8, 8, BufferedImage.TYPE_INT_ARGB);
	char[] temp = s.toUpperCase().toCharArray();
	Graphics g = ret.getGraphics();
	int y = 8 * flag;
	for (int i = 0; i < temp.length; i++) {
		int loc = CHARS.indexOf(temp[i]);
		BufferedImage t = FONT_SPRITES.getSubimage(loc * 8, y, 8, 8);
		g.drawImage(t, i * 8, 0, null);
	}
	return ret;
}
 
开发者ID:fatmanspanda,项目名称:ALTTPMenuPractice,代码行数:19,代码来源:MenuGameConstants.java

示例7: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
    BufferedImage im = getWhiteImage(30, 30);
    Graphics2D g2 = (Graphics2D)im.getGraphics();
    g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);
    g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    g2.setBackground(Color.white);
    g2.setColor(Color.black);

    Path2D p = getPath(0, 0, 20);
    g2.draw(p);

    if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) {
        throw new Exception("This pixel should be black");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:Test7019861.java

示例8: getAppIconImageCompositedOn

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
static BufferedImage getAppIconImageCompositedOn(final Image background, int scaleFactor) {

        final int scaledAlertIconSize = kAlertIconSize * scaleFactor;
        final int kAlertSubIconSize = (int) (scaledAlertIconSize * 0.5);
        final int kAlertSubIconInset = scaledAlertIconSize - kAlertSubIconSize;
        final Icon smallAppIconScaled = new AquaIcon.CachingScalingIcon(
                kAlertSubIconSize, kAlertSubIconSize) {
                    Image createImage() {
                        return getGenericJavaIcon();
                    }
                };

        final BufferedImage image = new BufferedImage(scaledAlertIconSize,
                scaledAlertIconSize, BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics g = image.getGraphics();
        g.drawImage(background, 0, 0,
                scaledAlertIconSize, scaledAlertIconSize, null);
        if (g instanceof Graphics2D) {
            // improves icon rendering quality in Quartz
            ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING,
                    RenderingHints.VALUE_RENDER_QUALITY);
        }

        smallAppIconScaled.paintIcon(null, g,
                kAlertSubIconInset, kAlertSubIconInset);
        g.dispose();

        return image;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:AquaImageFactory.java

示例9: getBGTileIcon

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public Image getBGTileIcon(Rectangle bounds) {
	BufferedImage bi = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	g.setColor(new Color(150, 150, 150, 200));
	g.fillRect(0, 0, bounds.width, bounds.height);
	return bi;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:9,代码来源:SampleQNAnimation.java

示例10: createQRImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static void createQRImage(File qrFile, String qrCodeText, int size, String fileType)
		throws WriterException, IOException {
	// Create the ByteMatrix for the QR-Code that encodes the given String
	Hashtable hintMap = new Hashtable();
	hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
	QRCodeWriter qrCodeWriter = new QRCodeWriter();
	BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
	// Make the BufferedImage that are to hold the QRCode
	int matrixWidth = byteMatrix.getWidth();
	BufferedImage image = new BufferedImage(matrixWidth, matrixWidth, BufferedImage.TYPE_INT_RGB);
	image.createGraphics();

	Graphics2D graphics = (Graphics2D) image.getGraphics();
	graphics.setColor(Color.WHITE);
	graphics.fillRect(0, 0, matrixWidth, matrixWidth);
	// Paint and save the image using the ByteMatrix
	graphics.setColor(Color.BLACK);

	for (int i = 0; i < matrixWidth; i++) {
		for (int j = 0; j < matrixWidth; j++) {
			if (byteMatrix.get(i, j)) {
				graphics.fillRect(i, j, 1, 1);
			}
		}
	}
	ImageIO.write(image, fileType, qrFile);
}
 
开发者ID:ameijer,项目名称:bitcoin_wallet_recovery_tool,代码行数:28,代码来源:Main.java

示例11: draw

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImage draw(Petrinet petrinet){
	petriConverter.clearPetriConverter();
	petriConverter.convertPetri(petrinet);
	petriWindow.updateGraph(petriConverter.nodes, petriConverter.edges);
	
	BufferedImage bi = (BufferedImage) petriWindow.createImage(petriWindow.getWidth(), petriWindow.getHeight());
	bi.createGraphics();
	Graphics g = bi.getGraphics();
	petriWindow.paint(g);
	return bi;					
}
 
开发者ID:tslaats,项目名称:SE2017-Team2,代码行数:12,代码来源:PetriDrawer.java

示例12: createImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static Image createImage(final int length, final Color color) {

        final BufferedImage image = new BufferedImage(length, length,
                BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics graphics = image.getGraphics();
        graphics.setColor(color);
        graphics.fillRect(0, 0, length, length);
        graphics.dispose();
        return image;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:MultiResolutionDragImageTest.java

示例13: createFontMetrics

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private void createFontMetrics() 
{
	BufferedImage baseImage = new BufferedImage(1, 1,
			BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = (Graphics2D) baseImage.getGraphics();
	fontMetrics = g.getFontMetrics(font);
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:8,代码来源:FontFactory.java

示例14: cutImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**截取图像*/  
public static BufferedImage cutImage(BufferedImage bufferedImage, int w, int h,int x,int y){
	BufferedImage distin = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
	Graphics g = distin.getGraphics();
	g.drawImage(bufferedImage, 0, 0, w, h, x, y, x+w, y+h, null);
	/*try {
		ImageIO.write(distin, "jpg", new File("E:/IMG/test/"+x+".jpg"));
	} catch (IOException e) {
		e.printStackTrace();
	}*/
	return distin;
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:13,代码来源:ImageCognition.java

示例15: updateTooltipImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private boolean updateTooltipImage(RenderedImage contents, int row, int col) {
            TableCellRenderer renderer = listClasses.getCellRenderer(row, col); 
            Component component = listClasses.prepareRenderer(renderer, row, col);
            
            if (!(component instanceof JComponent)) {
                // sorry.
                return false;
            }
            Rectangle cellRect = listClasses.getCellRect(row, col, false);
            Dimension size = component.getPreferredSize();
            Rectangle visibleRect = listClasses.getVisibleRect();
            
            // The visible region is wide enough, hide the tooltip
            if (cellRect.width >= size.width) {
                hidePopup();
                return false;
            }           
            // Hide if the cell does not vertically fit
            if (cellRect.y + size.height > visibleRect.y + visibleRect.height + 1) {
                hidePopup();
                return false;
            }
            BufferedImage img = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
            Graphics g = img.getGraphics();
            g.setClip(null);
            g.setColor(listClasses.getBackground());
            g.fillRect(0, 0, size.width, size.height);
            g.translate(-cellRect.x, -cellRect.y);
//            g.translate(-visibleRect.x, -visibleRect.y);
            
            cellRect.width = size.width;
            // prevent some repaing issues, see javadoc for CellRendererPane.
            rendererPane.paintComponent(g, component, listClasses, cellRect);
            
            // if table displays lines, frame the cell's display using lines.
            if (listClasses.getShowHorizontalLines()) {
                int rightX = size.width - 1;
                g.translate(cellRect.x, cellRect.y);
                g.setColor(listClasses.getForeground());
                g.drawLine(0, 0, rightX, 0);
                g.drawLine(rightX, 0, rightX, size.height);
                g.drawLine(rightX, size.height - 1, 0, size.height - 1);
            }
            g.dispose();
            rendererPane.remove(component);
            contents.setImage(img);
            return true;
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:InnerPanelSupport.java


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