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


Java BufferedImage.createGraphics方法代码示例

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


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

示例1: dumpSceneOffscreenRendering

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private BufferedImage dumpSceneOffscreenRendering (Scene scene) {
    // validate the scene with a off-screen graphics
    BufferedImage emptyImage = new BufferedImage (1, 1, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D emptyGraphics = emptyImage.createGraphics ();
    scene.validate (emptyGraphics);
    emptyGraphics.dispose ();

    // now the scene is calculated using the emptyGraphics, all widgets should be layout and scene has its size resolved
    // paint the scene with a off-screen graphics
    Rectangle viewBounds = scene.convertSceneToView (scene.getBounds ());
    BufferedImage image = new BufferedImage (viewBounds.width, viewBounds.height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D graphics = image.createGraphics ();
    double zoomFactor = scene.getZoomFactor ();
    graphics.scale (zoomFactor, zoomFactor);
    scene.paint (graphics);
    graphics.dispose ();

    return image;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:OffscreenRenderingTest.java

示例2: paint

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public void paint(Graphics g)
{
    // Gets the canvas to draw in
    BufferedImage bi = new BufferedImage(
        Constant.BOARD_CELL_SIZE * board.countColumns(),
        Constant.BOARD_CELL_SIZE * board.countRows(),
        BufferedImage.TYPE_INT_RGB
    );
    
    Graphics2D canvas = bi.createGraphics();

    // Draws the game in the canvas
    for (int i = 0; i < board.countRows(); ++i)
    {
        for (int j = 0; j < board.countColumns(); ++j)
        {
            board.getCell(new Coord2D(i, j)).draw(canvas);
        }
    }
    
    // Really paints the component
    ((Graphics2D) g).drawImage(bi, 0, 0, this);
}
 
开发者ID:wguilen,项目名称:pacman-mas,代码行数:25,代码来源:BoardGui.java

示例3: exportGraphic

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@SuppressWarnings("SpellCheckingInspection")
void exportGraphic(String dir, String name, GraphicsExporter exporter) {
	try {
		PDDocument document = new PDDocument();

		PDFont pdArial = PDFontFactory.createDefaultFont();

		File parentDir = new File("target/test/" + dir);
		// noinspection ResultOfMethodCallIgnored
		parentDir.mkdirs();

		BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_4BYTE_ABGR);
		Graphics2D imageGraphics = image.createGraphics();
		exporter.draw(imageGraphics);
		imageGraphics.dispose();
		ImageIO.write(image, "PNG", new File(parentDir, name + ".png"));

		for (Mode m : Mode.values()) {
			PDPage page = new PDPage(PDRectangle.A4);
			document.addPage(page);

			PDPageContentStream contentStream = new PDPageContentStream(document, page);
			PdfBoxGraphics2D pdfBoxGraphics2D = new PdfBoxGraphics2D(document, 400, 400);
			PdfBoxGraphics2DFontTextDrawer fontTextDrawer = null;
			contentStream.beginText();
			contentStream.setStrokingColor(0, 0, 0);
			contentStream.setNonStrokingColor(0, 0, 0);
			contentStream.setFont(PDType1Font.HELVETICA_BOLD, 15);
			contentStream.setTextMatrix(Matrix.getTranslateInstance(10, 800));
			contentStream.showText("Mode " + m);
			contentStream.endText();
			switch (m) {
			case FontTextIfPossible:
				fontTextDrawer = new PdfBoxGraphics2DFontTextDrawer();
				fontTextDrawer.registerFont(
						new File("src/test/resources/de/rototor/pdfbox/graphics2d/DejaVuSerifCondensed.ttf"));
				break;
			case DefaultFontText: {
				fontTextDrawer = new PdfBoxGraphics2DFontTextDrawerDefaultFonts();
				fontTextDrawer.registerFont(
						new File("src/test/resources/de/rototor/pdfbox/graphics2d/DejaVuSerifCondensed.ttf"));
				break;
			}
			case ForceFontText:
				fontTextDrawer = new PdfBoxGraphics2DFontTextForcedDrawer();
				fontTextDrawer.registerFont(
						PdfBoxGraphics2DTestBase.class.getResourceAsStream("DejaVuSerifCondensed.ttf"));
				fontTextDrawer.registerFont("Arial", pdArial);
				break;
			case DefaultVectorized:
			default:
				break;
			}

			if (fontTextDrawer != null) {
				pdfBoxGraphics2D.setFontTextDrawer(fontTextDrawer);
			}

			exporter.draw(pdfBoxGraphics2D);
			pdfBoxGraphics2D.dispose();

			PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
			Matrix matrix = new Matrix();
			matrix.translate(0, 20);
			contentStream.transform(matrix);
			contentStream.drawForm(appearanceStream);

			matrix.scale(1.5f, 1.5f);
			matrix.translate(0, 100);
			contentStream.transform(matrix);
			contentStream.drawForm(appearanceStream);
			contentStream.close();
		}

		document.save(new File(parentDir, name + ".pdf"));
		document.close();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:81,代码来源:PdfBoxGraphics2DTestBase.java

示例4: call

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public byte[] call() throws Exception {
	BufferedImage original = ImageIO.read(_image_in);
	float ratio = (float)original.getHeight()/(float)original.getWidth();
	
	//if height > width take max_height else resize  
	int thumb_height = ratio>=1?MAX_HEIGHT:(int) (MAX_HEIGHT*ratio);
	//if width > height max_width else multiply by ratio
	int thumb_width = ratio<=1?MAX_WIDTH:(int) (MAX_WIDTH/ratio);
					
	BufferedImage result = new BufferedImage(thumb_width, thumb_height, original.getType());
	Graphics2D g = result.createGraphics();
	g.drawImage(original, 0, 0, thumb_width, thumb_height, null);
	g.dispose();
				
	ByteArrayOutputStream os = new ByteArrayOutputStream();
       ImageIO.write(result, _file_name.substring(_file_name.lastIndexOf(".")+1), os);
       
       return os.toByteArray();
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:21,代码来源:ContentFacade.java

示例5: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    Iterator witer = ImageIO.getImageWritersByFormatName("png");
    ImageWriter w = (ImageWriter)witer.next();

    File f = File.createTempFile("WriteProgressive", ".png");
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    w.setOutput(ios);

    BufferedImage bi = new BufferedImage(100, 100,
                                         BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = bi.createGraphics();
    Random r = new Random(10);
    for (int i = 0; i < 10000; i++) {
        Color c =
            new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
        g.setColor(c);
        g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1);
    }

    IIOImage iioimage = new IIOImage(bi, null, null);

    ImageWriteParam param = w.getDefaultWriteParam();
    param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);

    try {
        w.write(null, iioimage, param);
    } catch (NullPointerException npe) {
        throw new RuntimeException("Got NPE during write!");
    }

    ios.close();

    BufferedImage bi2 = ImageIO.read(f);
    f.delete();

    ImageCompare.compare(bi, bi2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:WriteProgressive.java

示例6: TextureWatchFX

import java.awt.image.BufferedImage; //导入方法依赖的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();
    }
}
 
开发者ID:jd-lang,项目名称:betaexpansion,代码行数:33,代码来源:TextureWatchFX.java

示例7: convertType

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
BufferedImage convertType(BufferedImage src, int targetType) {
	if (src.getType() == targetType) {
		return src;
	}
	BufferedImage tgt = new BufferedImage(src.getWidth(), src.getHeight(), targetType);
	Graphics2D g = tgt.createGraphics();
	g.drawRenderedImage(src, null);
	g.dispose();
	return tgt;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:11,代码来源:PAResultsWindow.java

示例8: resizeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int IMG_HEIGHT, int IMG_WIDTH) {
	BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
	Graphics2D g = resizedImage.createGraphics();
	g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
	g.dispose();

	return resizedImage;
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:9,代码来源:Convolution.java

示例9: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
  Graphics2D g = image.createGraphics();

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setPaint(Color.WHITE);
  g.fill(new Rectangle(image.getWidth(), image.getHeight()));

  g.scale(0.5 / PIXEL, 0.5 / PIXEL);
  g.setPaint(Color.BLACK);
  g.setStroke(new BasicStroke(PIXEL));
  g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));

  // To visually check it
  //ImageIO.write(image, "PNG", new File(args[0]));

  boolean nonWhitePixelFound = false;
  for (int x = 0; x < 200; ++x) {
    if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
      nonWhitePixelFound = true;
      break;
    }
  }
  if (!nonWhitePixelFound) {
    throw new RuntimeException("The thin line disappeared.");
  }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:ThinLineTest.java

示例10: transform

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void transform(String originalFile, String thumbnailFile, int thumbWidth, int thumbHeight, int quality) throws Exception 
{
	Image image = javax.imageio.ImageIO.read(new File(originalFile));
    
    double thumbRatio = (double)thumbWidth / (double)thumbHeight;
    int imageWidth    = image.getWidth(null);
    int imageHeight   = image.getHeight(null);
    double imageRatio = (double)imageWidth / (double)imageHeight;
    if (thumbRatio < imageRatio) 
    {
    	thumbHeight = (int)(thumbWidth / imageRatio);
    } 
    else 
    {
      	thumbWidth = (int)(thumbHeight * imageRatio);
    }
    
	if(imageWidth < thumbWidth && imageHeight < thumbHeight)
	{
		thumbWidth = imageWidth;
		thumbHeight = imageHeight;
	}
	else if(imageWidth < thumbWidth)
		thumbWidth = imageWidth;
	else if(imageHeight < thumbHeight)
		thumbHeight = imageHeight;

    BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setBackground(Color.WHITE);
   	graphics2D.setPaint(Color.WHITE); 
   	graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    
	javax.imageio.ImageIO.write(thumbImage, "JPG", new File(thumbnailFile));
}
 
开发者ID:LuJiangLin,项目名称:TestDemo1-github,代码行数:38,代码来源:ThumbnailGenerator.java

示例11: getBufferedImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static BufferedImage getBufferedImage(int sw) {
    BufferedImage bi = new BufferedImage(sw, sw,
                                         BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, sw, sw);
    return bi;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:IncorrectClipSurface2SW.java

示例12: getFullImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Get the full image, not just the visible portion
 */
public BufferedImage getFullImage() {
	Rectangle r = new Rectangle (0, 0, getWidth(), getHeight());
	BufferedImage image = new BufferedImage(r.width, r.height,
			BufferedImage.TYPE_INT_RGB);
	Graphics2D g = image.createGraphics();
	g.translate( -r.x, -r.y);
	paintComponent( g, true, false );
	return image;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:13,代码来源:XYGraph.java

示例13: getImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public Image getImage() {
	BufferedImage image =
           new BufferedImage(getIconWidth(), getIconHeight(),
                   BufferedImage.TYPE_INT_ARGB);
   	Graphics2D g = image.createGraphics();
   	paintIcon(null, g, 0, 0);
   	g.dispose();
   	return image;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:10,代码来源:CorpusBenchmarkIcon.java

示例14: clip

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public ImageUtils clip(int srcX, int srcY, int width, int height){
    BufferedImage newImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = newImg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, width, height);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(this.dealedImage, 0, 0, width, height, srcX, srcY, srcX + width, srcY + height, null);
    this.dealedImage = newImg;
    g.dispose();

    return this;
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:14,代码来源:ImageUtils.java

示例15: resizeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
static BufferedImage resizeImage(BufferedImage originalImage) {
    int imageType = originalImage.getType();
    if (imageType == 0) imageType = 5;

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, imageType);

    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

    return resizedImage;
}
 
开发者ID:kevalpatel2106,项目名称:EmoticonGIFKeyboard,代码行数:13,代码来源:Utils.java


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