本文整理汇总了Java中java.awt.Graphics2D.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setBackground方法的具体用法?Java Graphics2D.setBackground怎么用?Java Graphics2D.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.setBackground方法的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;
}
示例2: main
import java.awt.Graphics2D; //导入方法依赖的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");
}
}
示例3: 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();
}
}
}
示例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;
}
示例5: createImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected BufferedImage createImage(Color bgColor) {
BufferedImage bufferedImage = new BufferedImage(END_X, END_Y,
BufferedImage.TYPE_INT_RGB);
// create graphics and graphics2d
final Graphics graphics = bufferedImage.getGraphics();
final Graphics2D g2d = (Graphics2D) graphics;
// set the background color
g2d.setBackground(bgColor == null ? Color.gray : bgColor);
g2d.clearRect(START_X, START_Y, END_X, END_Y);
// create a pattern for the background
createPattern(g2d);
// set the fonts and font rendering hints
Font font = new Font("Helvetica", Font.ITALIC, 30);
g2d.setFont(font);
FontRenderContext frc = g2d.getFontRenderContext();
g2d.translate(10, 24);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(3));
// sets the foreground color
g2d.setPaint(Color.DARK_GRAY);
GlyphVector gv = font.createGlyphVector(frc, message);
int numGlyphs = gv.getNumGlyphs();
for (int ii = 0; ii < numGlyphs; ii++) {
AffineTransform at;
Point2D p = gv.getGlyphPosition(ii);
at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
at.rotate(Math.PI / 8);
Shape shape = gv.getGlyphOutline(ii);
Shape sss = at.createTransformedShape(shape);
g2d.fill(sss);
}
return blurImage(bufferedImage);
}
示例6: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void draw(Graphics2D g2) {
Coord c,c2;
if (simMap == null) {
return;
}
g2.setColor(PATH_COLOR);
g2.setBackground(BG_COLOR);
// draws all edges between map nodes (bidirectional edges twice)
for (MapNode n : simMap.getNodes()) {
c = n.getLocation();
// draw a line to adjacent nodes
for (MapNode n2 : n.getNeighbors()) {
c2 = n2.getLocation();
g2.drawLine(scale(c2.getX()), scale(c2.getY()),
scale(c.getX()), scale(c.getY()));
}
}
}
示例7: 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);
}
示例8: doCreateBackgroundImages
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Method description
*
* @see
*/
final public void doCreateBackgroundImages() {
// Tools.verbose("On rentre dans doCreateBackgroundImages()");
this.imgGbackgroundBufferA = new BufferedImage[2];
for (int intLbackgroundIndex = Constants.bytS_ENGINE_NIGHT; intLbackgroundIndex <= Constants.bytS_ENGINE_DAY; ++intLbackgroundIndex) {
this.imgGbackgroundBufferA[intLbackgroundIndex] =
Constants.objS_GRAPHICS_CONFIGURATION.createCompatibleImage(Constants.intS_GRAPHICS_SCREEN_WIDTH,
Constants.intS_GRAPHICS_SCREEN_HEIGHT,
Transparency.OPAQUE);
final Graphics2D objLbackgroundGraphics2D = (Graphics2D) this.imgGbackgroundBufferA[intLbackgroundIndex].getGraphics();
objLbackgroundGraphics2D.setBackground(this.objGjuggleMasterPro.objGbackgroundColorA[intLbackgroundIndex]);
objLbackgroundGraphics2D.setColor(this.objGjuggleMasterPro.objGbackgroundColorA[intLbackgroundIndex]);
objLbackgroundGraphics2D.fillRect(0, 0, Constants.intS_GRAPHICS_SCREEN_WIDTH, Constants.intS_GRAPHICS_SCREEN_HEIGHT);
objLbackgroundGraphics2D.dispose();
}
}
示例9: mergeAll
import java.awt.Graphics2D; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public void mergeAll(String mergedName) {
try {
System.out.print("이미지 병합중 ... ");
int i, len, preHeight, width, maxWidth = -1, totalHeight = -1;
/* 폴더 내부의 모든 이미지(jpg, bmp등)를 얻음 */
File images[] = root.listFiles(f-> f.getName().matches(imgExt));
BufferedImage bi[] = new BufferedImage[len = images.length];
for(i=0;i<len;i++) {
bi[i] = ImageIO.read(images[i]);
maxWidth = Math.max(maxWidth, width = bi[i].getWidth()); //생성될 통합파일의 너비 계산
totalHeight += bi[i].getHeight(); //생성될 통합파일의 총 높이 계산
}
/* 통합 이미지. 최대 너비 x 총 높이 */
BufferedImage mergedImage = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = (Graphics2D) mergedImage.getGraphics();
graphics.setBackground(Color.BLACK); //여백은 검정으로 채움
graphics.drawImage(bi[0], 0, 0, null); //처음엔 (0, 0)에 그리기
preHeight = bi[0].getHeight();
for(i=1;i<len;i++) {
graphics.drawImage(bi[i], 0, preHeight, null);
preHeight += bi[i].getHeight(); //높이를 누산해야됨
}
/* 병합된 이미지를 최종적으로 write */
ImageIO.write(mergedImage, "jpg", new File(root+"/" + mergedName + ".jpg"));
} catch (Exception e) {
ErrorHandling.saveErrLog("이미지 병합 실패: "+mergedName, "", e);
return;
}
System.out.println("성공");
}
示例10: drawFlagImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void drawFlagImage(Graphics2D g) {
final int tabHeight = 15;
final int tabWidth = 10;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setColor(background);
g.fillRoundRect(-tabWidth, 0, 2*tabWidth, tabHeight, 6, 6);
g.setColor(foreground);
g.drawRoundRect(-tabWidth, 0, 2*tabWidth-1, tabHeight-1, 6, 6);
g.setFont(new Font("Dialog", Font.PLAIN, 9));
Rectangle2D r = g.getFontMetrics().getStringBounds(name, g);
g.drawString(name, tabWidth/2 - (int) (r.getWidth()/2.0) - 1, 11);
g.setBackground(new Color(0,0,0,0));
g.clearRect(-tabWidth, 0, tabWidth, tabHeight);
}
示例11: buildSizeImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage buildSizeImage(String size, int sym_w, int sym_h, int gap) {
SizeOption option = findSize(size);
String type = option.getType();
int count = option.getCount();
BufferedImage bi = createImage(count, sym_w, sym_h, gap);
Graphics2D g = bi.createGraphics();
g.setBackground(null);
g.setColor(Color.BLACK);
return buildSizeImage(g, count, type, sym_w, sym_h, gap);
}
示例12: 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);
}
示例13: apply
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void apply(Graphics2D g)
{
g.setTransform(transform);
g.setPaint(paint);
g.setStroke(stroke);
g.setFont(font);
g.setComposite(composite);
g.setBackground(bgrnd);
g.setClip(shape);
g.setRenderingHints(hints);
}
示例14: getBlank
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static ImageIcon getBlank(Dimension d) {
BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) bi.getGraphics();
g2.setBackground(new Color(0, 0, 0, 0));
g2.dispose();
return new ImageIcon(bi);
}
示例15: getGraphics
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public Graphics getGraphics() {
if (bbImage == null) return null;
Graphics2D g = bbImage.createGraphics();
g.setBackground(getBackground());
g.setColor(getForeground());
g.setFont(getFont());
g.scale(scaleFactor, scaleFactor);
return g;
}