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


Java Graphics2D.clearRect方法代码示例

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


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

示例1: convertPngToJpeg

import java.awt.Graphics2D; //导入方法依赖的package包/类
private String convertPngToJpeg(String pngBase64) throws IOException {
	byte[] pngBinary = DatatypeConverter.parseBase64Binary(pngBase64);
	InputStream in = new ByteArrayInputStream(pngBinary);
	BufferedImage pngImage = ImageIO.read(in);

	int width = pngImage.getWidth(), height = pngImage.getHeight();
	BufferedImage jpgImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

	Graphics2D g = jpgImage.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	g.setBackground(Color.WHITE);
	g.clearRect(0, 0, width, height);
	g.drawImage(pngImage, 0, 0, width, height, null);
	g.dispose();

	final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	writer.setOutput(ImageIO.createImageOutputStream(baos));
	writer.write(null, new IIOImage(jpgImage, null, null), JPEG_PARAMS);

	String jpgBase64 = DatatypeConverter.printBase64Binary(baos.toByteArray());
	return jpgBase64;
}
 
开发者ID:JensN4,项目名称:png_to_jpg_in_svg,代码行数:24,代码来源:PNG_to_JPG_in_SVG.java

示例2: drawImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void drawImage(int size, FirmaGenLayer genlayer, String name) {
	try {
		File outFile = new File(name + ".bmp");
		if (outFile.exists())
			return;
		int[] ints = genlayer.getInts(0, 0, size, size);
		BufferedImage outBitmap = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
		Graphics2D graphics = (Graphics2D) outBitmap.getGraphics();
		graphics.clearRect(0, 0, size, size);
		for (int x = 0; x < size; x++) {
			for (int z = 0; z < size; z++) {
				if (ints[x * size + z] != -1 && FirmaBiome.getBiomeList()[ints[x * size + z]] != null) {
					graphics.setColor(Color.getColor("", ((FirmaBiome) Biome.getBiome(ints[x * size + z])).getBiomeColor()));
					graphics.drawRect(x, z, 1, 1);
				}
			}
		}
		System.out.println(outFile.getAbsolutePath());
		ImageIO.write(outBitmap, "BMP", outFile);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:trigg,项目名称:Firma,代码行数:24,代码来源:FirmaGenLayer.java

示例3: paintDisplayerBackground

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintDisplayerBackground( Graphics g, JComponent c ) {

    int x = 0;
    int y = 0;
    int width = c.getWidth();
    int height = c.getHeight();
    
    Object o = null;
    o = UIManager.get("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter");

    if ((o != null) && (o instanceof javax.swing.Painter)) {
        javax.swing.Painter painter = (javax.swing.Painter) o;
        BufferedImage bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bufIm.createGraphics();
        g2d.setBackground(UIManager.getColor("Panel.background"));
        g2d.clearRect(0, 0, width, height);
        painter.paint(g2d, null, width, height);
        g.drawImage(bufIm, x, y, null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:NimbusViewTabDisplayerUI.java

示例4: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
boolean draw(Graphics2D g) {
  // set background color
  g.setBackground(tableColor);
  Dimension d = getLayout().getBoardSize();
  g.clearRect(0, 0, d.width, d.height);

  // See if map image file exists
  File sml = action.getCaseInsensitiveFile(new File(forceExtension(path, "sml")), null, false, null);
  if (sml != null) {
    try {
      readScannedMapLayoutFile(sml, g);
    }
    // FIXME: review error message
    catch (IOException e) {}
  }
  else if (getSet().underlay != null) {
    // If sml file doesn't exist, see if there is a single-sheet underlay image
  g.drawImage(getSet().underlay, null, 0, 0);
  }
  return true;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:23,代码来源:MapBoard.java

示例5: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    super.paint(g);
    if (sensor == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.setBackground(Color.WHITE);
    g2.clearRect(0, 0, getWidth(), getHeight());
    g2.setColor(Color.RED);
    g2.setStroke(new BasicStroke(2f));
    ToradexOakG3AxisAccelerationSensor.Acceleration v=sensor.getAcceleration();
    int w=getWidth(), h=getHeight();
    final float m = ToradexOakG3AxisAccelerationSensor.MAX_ACCEL;
    float x = w*v.x/m+w/2;
    float y = h*v.y/m+h/2;
    float z = (v.z+m/2)/m*h/10;
    final int r = (int)z;
    int xx=(int)(x-r), yy=(int)(y-r);
    g2.drawOval(xx, yy, r * 2, r * 2);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:22,代码来源:ToradexOakG3AxisAccelerationSensorGUI.java

示例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();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:CGLGraphicsConfig.java

示例7: renderToBS

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void renderToBS() {
    width = getWidth();
    height = getHeight();

    do {
        Graphics2D g2d = (Graphics2D)bufferStrategy.getDrawGraphics();

        g2d.clearRect(0, 0, width, height);
        synchronized (balls) {
            for (Ball b : balls) {
                b.move();
                b.paint(g2d, null);
            }
        }
        g2d.dispose();
    } while (bufferStrategy.contentsLost() ||
            bufferStrategy.contentsRestored());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AltTabCrashTest.java

示例8: paintTabBackground

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void paintTabBackground (Graphics g, int index, Component c,
int x, int y, int w, int h) {

    Shape clip = g.getClip();
    NimbusEditorTabCellRenderer ren = (NimbusEditorTabCellRenderer) c;

    w +=1;
    boolean isPreviousTabSelected = ren.isPreviousTabSelected();
    if (isPreviousTabSelected) {
        g.setClip(x+1, y, w-1, h);
    }

    Object o = null;
    if (ren.isSelected()) {
        if (ren.isActive()) {
            o = UIManager.get("TabbedPane:TabbedPaneTab[MouseOver+Selected].backgroundPainter");
        } else {
            o = UIManager.get("TabbedPane:TabbedPaneTab[Selected].backgroundPainter");
        }
    } else {
        o = UIManager.get("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter");
    }
    if ((o != null) && (o instanceof javax.swing.Painter)) {
        javax.swing.Painter painter = (javax.swing.Painter) o;
        BufferedImage bufIm = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bufIm.createGraphics();
        g2d.setBackground(UIManager.getColor("Panel.background"));
        g2d.clearRect(0, 0, w, h);
        painter.paint(g2d, null, w, h);
        g.drawImage(bufIm, x, y, null);
    }

    if (isPreviousTabSelected) {
        g.setClip(clip);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:NimbusEditorTabCellRenderer.java

示例9: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2d.clearRect(0, 0, this.getWidth(), this.getHeight());
	g2d.setStroke(dCst.getDrawStroke());
	changeDrawSettings(dCst);

	//draw jobs
	drawJobsRemaining(donejobs, totjobs, panelW * 0.15f, 10.0f, panelW * 0.7f, panelH / 2.0f, g2d);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:12,代码来源:JobsDrawer.java

示例10: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2d.clearRect(0, 0, this.getWidth(), this.getHeight());
	g2d.setStroke(dCst.getDrawStroke());
	changeDrawSettings(dCst);

	//disegna jobs
	drawJobsRemaining(donejobs, totjobs, panelW * 0.15f, 10.0f, panelW * 0.7f, panelH / 2.0f, g2d);
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:12,代码来源:JobsDrawer.java

示例11: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws the play field. To be called by Swing framework or directly if
 * different context than screen is desired
 * @param g The graphics context to draw the field to
 */
public void paint(Graphics g) {
	Graphics2D g2 = (Graphics2D)g;
	g2.setBackground(bgColor);
	
	// clear old playfield graphics
	g2.clearRect(0, 0, this.getWidth(), this.getHeight());
	if (underlayImage != null) {
		g2.drawImage(underlayImage,curTransform, null);
	}

	// draw map (is exists and drawing requested)
	if (mapGraphic != null && showMapGraphic) {
		mapGraphic.draw(g2);
	}
	
	// draw hosts
	for (DTNHost h : w.getHosts()) {
		new NodeGraphic(h).draw(g2); // TODO: Optimization..?
	}
	
	// draw overlay graphics
	for (int i=0, n=overlayGraphics.size(); i<n; i++) {
		overlayGraphics.get(i).draw(g2);
	}
	
	// draw reference scale
	this.refGraphic.draw(g2);
}
 
开发者ID:MaX121,项目名称:Bachelor-Thesis,代码行数:34,代码来源:PlayField.java

示例12: initSurface

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void initSurface(int width, int height) {
    Graphics2D g2 = createGraphics();
    try {
        g2.clearRect(0, 0, width, height);
    } finally {
        g2.dispose();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:OffScreenImage.java

示例13: load

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public boolean load(IResourceManager manager, ResourceLocation location)
{
    BufferedImage image = new BufferedImage(this.getIconWidth(), this.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setBackground(Color.WHITE);
    graphics.clearRect(0, 0, this.getIconWidth(), this.getIconHeight());
    int[][] pixels = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
    pixels[0] = new int[image.getWidth() * image.getHeight()];
    image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels[0], 0, image.getWidth());
    this.clearFramesTextureData();
    this.framesTextureData.add(pixels);
    return false;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:15,代码来源:ModelLoader.java

示例14: test

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void test(final float lineStroke,
                             final boolean useDashes,
                             final float dashMinLen)
        throws ArrayIndexOutOfBoundsException
    {
        System.out.println("---\n" + "test: "
            + "lineStroke=" + lineStroke
            + ", useDashes=" + useDashes
            +", dashMinLen=" + dashMinLen
        );

        final BasicStroke stroke = createStroke(lineStroke, useDashes, dashMinLen);

        // TODO: test Dasher.firstSegmentsBuffer resizing ?
// array.dasher.firstSegmentsBuffer.d_float[2] sum: 6 avg: 3.0 [3 | 3]
        /*
         // Marlin growable arrays:
         = new StatLong("array.dasher.firstSegmentsBuffer.d_float");
         = new StatLong("array.stroker.polystack.curves.d_float");
         = new StatLong("array.stroker.polystack.curveTypes.d_byte");
         = new StatLong("array.marlincache.rowAAChunk.d_byte");
         = new StatLong("array.marlincache.touchedTile.int");
         = new StatLong("array.renderer.alphaline.int");
         = new StatLong("array.renderer.crossings.int");
         = new StatLong("array.renderer.aux_crossings.int");
         = new StatLong("array.renderer.edgeBuckets.int");
         = new StatLong("array.renderer.edgeBucketCounts.int");
         = new StatLong("array.renderer.edgePtrs.int");
         = new StatLong("array.renderer.aux_edgePtrs.int");
         */
        // size > 8192 (exceed both tile and buckets arrays)
        final int size = 9000;
        System.out.println("image size = " + size);

        final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

        final Graphics2D g2d = (Graphics2D) image.getGraphics();
        try {
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

            g2d.setClip(0, 0, size, size);
            g2d.setBackground(Color.WHITE);
            g2d.clearRect(0, 0, size, size);

            g2d.setStroke(stroke);
            g2d.setColor(Color.BLACK);

            final long start = System.nanoTime();

            paint(g2d, size - 10f);

            final long time = System.nanoTime() - start;

            System.out.println("paint: duration= " + (1e-6 * time) + " ms.");

            if (SAVE_IMAGE) {
                try {
                    final File file = new File("CrashTest-dash-" + useDashes + ".bmp");

                    System.out.println("Writing file: " + file.getAbsolutePath());
                    ImageIO.write(image, "BMP", file);
                } catch (IOException ex) {
                    System.out.println("Writing file failure:");
                    ex.printStackTrace();
                }
            }
        } finally {
            g2d.dispose();
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:72,代码来源:CrashTest.java

示例15: paintTabBackground

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintTabBackground(Graphics g, int index, int x, int y,
                                  int width, int height) {
    boolean isLast = index == getDataModel().size()-1;
    if (!isLast) {
        width++;
    }

    Shape clip = g.getClip();
    boolean isPreviousTabSelected = index-1 == displayer.getSelectionModel().getSelectedIndex();
    if (isPreviousTabSelected) {
        g.setClip(x+1, y, width-1, height);
    }

    final boolean attention = isAttention(index);
    Object o = null;
    if (isSelected(index)) {
        String mouseOver = "TabbedPane:TabbedPaneTab[MouseOver+Selected].backgroundPainter";
        String selected = "TabbedPane:TabbedPaneTab[Selected].backgroundPainter";
        if (isActive()) {
            o = UIManager.get( attention ? selected : mouseOver);
        } else {
            o = UIManager.get( attention ? mouseOver: selected);
        }
    } else {
        if( attention ) {
            o = UIManager.get("TabbedPane:TabbedPaneTab[Disabled].backgroundPainter");
        } else {
            o = UIManager.get("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter");
        }
    }

    if ((o != null) && (o instanceof javax.swing.Painter)) {
        javax.swing.Painter painter = (javax.swing.Painter) o;
        BufferedImage bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bufIm.createGraphics();
        g2d.setBackground(UIManager.getColor("Panel.background"));
        g2d.clearRect(0, 0, width, height);
        painter.paint(g2d, null, width, height);
        g.drawImage(bufIm, x, y, null);
    }

    if (isPreviousTabSelected) {
        g.setClip(clip);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:NimbusViewTabDisplayerUI.java


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