本文整理了Java中java.awt.Graphics2D.clearRect()
方法的一些代码示例,展示了Graphics2D.clearRect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.clearRect()
方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:clearRect
暂无
代码示例来源:origin: stackoverflow.com
public static BufferedImage transformImage(BufferedImage image, AffineTransform transform) throws Exception {
AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);
BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null );
Graphics2D g = destinationImage.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
destinationImage = op.filter(image, destinationImage);
return destinationImage;
}
代码示例来源:origin: stackoverflow.com
public BufferedImage scaleImage(BufferedImage img, int width, int height,
Color background) {
int imgWidth = img.getWidth();
int imgHeight = img.getHeight();
if (imgWidth*height < imgHeight*width) {
width = imgWidth*height/imgHeight;
} else {
height = imgHeight*width/imgWidth;
}
BufferedImage newImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = newImage.createGraphics();
try {
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setBackground(background);
g.clearRect(0, 0, width, height);
g.drawImage(img, 0, 0, width, height, null);
} finally {
g.dispose();
}
return newImage;
}
代码示例来源:origin: redwarp/9-Patch-Resizer
private void enforceBorderColors(BufferedImage inputImage) {
Graphics2D g = inputImage.createGraphics();
g.setBackground(new Color(0, 0, 0, 0));
g.clearRect(1, 1, inputImage.getWidth() - 2, inputImage.getHeight() - 2);
g.dispose();
int w = inputImage.getWidth();
int h = inputImage.getHeight();
int[] rgb = new int[w * h];
inputImage.getRGB(0, 0, w, h, rgb, 0, w);
for (int i = 0; i < rgb.length; i++) {
if ((0xff000000 & rgb[i]) != 0) {
rgb[i] = 0xff000000;
}
}
inputImage.setRGB(0, 0, w, h, rgb, 0, w);
inputImage.setRGB(0, 0, 0x0);
inputImage.setRGB(0, h - 1, 0x0);
inputImage.setRGB(w - 1, h - 1, 0x0);
inputImage.setRGB(w - 1, 0, 0x0);
}
代码示例来源:origin: jersey/jersey
@Path("discrete")
@GET
public Response discrete(
@DefaultValue("2") @QueryParam("width") final int width,
@DefaultValue("50") @QueryParam("upper") final int upper,
@DefaultValue("red") @QueryParam("upper-color") final ColorParam upperColor,
@DefaultValue("gray") @QueryParam("lower-color") final ColorParam lowerColor
) {
final BufferedImage image = new BufferedImage(
data.size() * width - 1, imageHeight, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, image.getWidth(), image.getHeight());
final int gap = 4;
final float d = (limits.width() + 1) / (float) (imageHeight - gap);
for (int i = 0, x = 0, y; i < data.size(); i++, x += width) {
final int v = data.get(i);
g.setColor((v >= upper) ? upperColor : lowerColor);
y = imageHeight - (int) ((v - limits.lower()) / d);
g.drawRect(x, y - gap, width - 2, gap);
}
return Response.ok(image).tag(tag).build();
}
代码示例来源:origin: loklak/loklak_server
/**
* Deletes all pixels of image and sets them to previously defined
* background color.
*/
public final void clear() {
// fill grid with background color
final int bgR = (int) (this.backgroundCol >> 16);
final int bgG = (int) ((this.backgroundCol >> 8) & 0xff);
final int bgB = (int) (this.backgroundCol & 0xff);
if (this.frame == null) {
final Graphics2D gr = this.image.createGraphics();
Color c = new Color(bgR, bgG, bgB);
gr.setBackground(c);
gr.clearRect(0, 0, this.width, this.height);
gr.setColor(c);
gr.fillRect(0, 0, this.width, this.height);
} else {
int p = 0;
for (int i = 0; i < width; i++) {
this.frame[p++] = (byte) bgR;
this.frame[p++] = (byte) bgG;
this.frame[p++] = (byte) bgB;
}
final int rw = width * 3;
for (int i = 1; i < height; i++) {
System.arraycopy(this.frame, 0, this.frame, i * rw, rw);
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
private void drawImage( SwingUniversalImage img, int centerX, int centerY, double angle, int imageSize ) {
if ( isDrawingPixelatedImages() && img.isBitmap() ) {
BufferedImage bi = img.getAsBitmapForSize( imageSize, imageSize, angle );
int offx = centerX + xOffset - bi.getWidth() / 2;
int offy = centerY + yOffset - bi.getHeight() / 2;
for ( int x = 0; x < bi.getWidth( observer ); x++ ) {
for ( int y = 0; y < bi.getHeight( observer ); y++ ) {
int rgb = bi.getRGB( x, y );
gc.setColor( new Color( rgb ) );
gc.setStroke( new BasicStroke( 1.0f ) );
gc.drawLine( offx + x, offy + y, offx + x, offy + y );
}
}
} else {
gc.setBackground( Color.white );
gc.clearRect( centerX, centerY, imageSize, imageSize );
img.drawToGraphics( gc, centerX, centerY, imageSize, imageSize, angle );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
private void drawImage( SwingUniversalImage img, int locationX, int locationY, int imageSize ) {
if ( isDrawingPixelatedImages() && img.isBitmap() ) {
BufferedImage bi = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB );
Graphics2D g2 = (Graphics2D) bi.getGraphics();
g2.setColor( Color.WHITE );
g2.fillRect( 0, 0, imageSize, imageSize );
g2.drawImage( img.getAsBitmapForSize( imageSize, imageSize ), 0, 0, observer );
g2.dispose();
for ( int x = 0; x < bi.getWidth( observer ); x++ ) {
for ( int y = 0; y < bi.getHeight( observer ); y++ ) {
int rgb = bi.getRGB( x, y );
gc.setColor( new Color( rgb ) );
gc.setStroke( new BasicStroke( 1.0f ) );
gc.drawLine( locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x, locationY
+ yOffset + y );
}
}
} else {
gc.setBackground( Color.white );
gc.clearRect( locationX, locationY, imageSize, imageSize );
img.drawToGraphics( gc, locationX, locationY, imageSize, imageSize );
}
}
代码示例来源:origin: jersey/jersey
data.size() * step - 4, imageHeight, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, image.getWidth(), image.getHeight());
代码示例来源:origin: chewiebug/GCViewer
public void render(GCModel model, FileOutputStream outputStream) throws IOException {
GCPreferences gcPreferences = new GCPreferences();
gcPreferences.load();
Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight());
BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
graphics.setBackground(Color.WHITE);
graphics.clearRect(0, 0, image.getWidth(), image.getHeight());
ChartDrawingParameters params
= new ChartDrawingParameters(model, gcPreferences, d, graphics, image, outputStream);
if (EventQueue.isDispatchThread()) {
drawAndSaveToStream(params);
}
else {
new SwingChartToStreamHelper().execute(params);
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
graphics.setBackground(Color.white);
graphics.clearRect(0, 0, width, height);
代码示例来源:origin: sarxos/webcam-capture
g2.setBackground(new Color(Math.abs(r++), Math.abs(g++), Math.abs(b++)));
g2.clearRect(0, 0, w, h);
代码示例来源:origin: looly/hutool
g.setBackground(fixedColor);
g.clearRect(0, 0, width, height);
代码示例来源:origin: looly/hutool
g.setBackground(fixedColor);
g.clearRect(0, 0, width, height);
代码示例来源:origin: nutzam/nutz
Graphics2D gc = tarIm.createGraphics();
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gc.setBackground(Strings.isBlank(bgColor) ? Colors.randomColor() : Colors.as(bgColor));
gc.clearRect(0, 0, width, height);
代码示例来源:origin: marytts/marytts
int image_toX = (int) width;
g.setBackground(backgroundColor);
g.clearRect(0, 0, (int) width, (int) height);
g.setFont(new Font("Courier", 0, 10));
代码示例来源:origin: marytts/marytts
int image_toX = (int) width;
g.setBackground(backgroundColor);
g.clearRect(0, 0, (int) width, (int) height);
g.setFont(new Font("Courier", 0, 10));
代码示例来源:origin: nutzam/nutz
Graphics2D gc = im.createGraphics();
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gc.setBackground(colorBg);
gc.clearRect(0, 0, width, height);
代码示例来源:origin: nutzam/nutz
gc = im.createGraphics();
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gc.setBackground(colorBg);
gc.clearRect(0, 0, width, height);
代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin
private static void enforceBorderColors(BufferedImage inputImage) {
Graphics2D g = inputImage.createGraphics();
g.setBackground(new Color(0, 0, 0, 0));
g.clearRect(1, 1, inputImage.getWidth() - 2, inputImage.getHeight() - 2);
g.dispose();
int w = inputImage.getWidth();
int h = inputImage.getHeight();
int[] rgb = new int[w * h];
inputImage.getRGB(0, 0, w, h, rgb, 0, w);
for (int i = 0; i < rgb.length; i++) {
if ((0xff000000 & rgb[i]) != 0) {
rgb[i] = 0xff000000;
}
}
inputImage.setRGB(0, 0, w, h, rgb, 0, w);
}
代码示例来源:origin: apache/pdfbox
private BufferedImage renderGlyph(GeneralPath path, Rectangle2D bounds2D, Rectangle cellRect)
{
BufferedImage bim = new BufferedImage((int) cellRect.getWidth(), (int) cellRect.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bim.getGraphics();
g.setBackground(Color.white);
g.clearRect(0, 0, bim.getWidth(), bim.getHeight());
double scale = 1 / ((yBounds[1] - yBounds[0]) / cellRect.getHeight());
// flip
g.scale(1, -1);
g.translate(0, -bim.getHeight());
// horizontal center
g.translate((cellRect.getWidth() - bounds2D.getWidth() * scale) / 2, 0);
// scale from the glyph to the cell
g.scale(scale, scale);
// Adjust for negative y min bound
g.translate(0, -yBounds[0]);
g.setColor(Color.black);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.fill(path);
g.dispose();
return bim;
}
}
内容来源于网络,如有侵权,请联系作者删除!