本文整理了Java中java.awt.image.BufferedImage.getGraphics()
方法的一些代码示例,展示了BufferedImage.getGraphics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedImage.getGraphics()
方法的具体详情如下:
包路径:java.awt.image.BufferedImage
类名称:BufferedImage
方法名:getGraphics
[英]This method returns a Graphics2D, but is here for backwards compatibility. #createGraphics() is more convenient, since it is declared to return a Graphics2D
.
[中]此方法返回一个Graphics2D,但此处是为了向后兼容#createGraphics()更方便,因为它被声明为返回一个Graphics2D
。
代码示例来源:origin: libgdx/libgdx
static Icon getColorIcon (java.awt.Color color) {
BufferedImage image = new BufferedImage(32, 16, BufferedImage.TYPE_INT_RGB);
java.awt.Graphics g = image.getGraphics();
g.setColor(color);
g.fillRect(1, 1, 30, 14);
g.setColor(java.awt.Color.black);
g.drawRect(0, 0, 31, 15);
return new ImageIcon(image);
}
代码示例来源:origin: stackoverflow.com
File path = ... // base path of the images
// load source images
BufferedImage image = ImageIO.read(new File(path, "image.png"));
BufferedImage overlay = ImageIO.read(new File(path, "overlay.png"));
// create the new image, canvas size is the max. of both image sizes
int w = Math.max(image.getWidth(), overlay.getWidth());
int h = Math.max(image.getHeight(), overlay.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(overlay, 0, 0, null);
// Save as new image
ImageIO.write(combined, "PNG", new File(path, "combined.png"));
代码示例来源:origin: javamelody/javamelody
private Bar(double percentValue, boolean alertOnHighUsage) {
super();
this.percentValue = percentValue;
this.alertOnHighUsage = alertOnHighUsage;
if (alertOnHighUsage) {
this.image = new BufferedImage(130, 14, BufferedImage.TYPE_INT_ARGB);
} else {
this.image = new BufferedImage(106, 10, BufferedImage.TYPE_INT_ARGB);
}
this.graphics = image.getGraphics();
}
代码示例来源:origin: graphhopper/graphhopper
protected BufferedImage makeARGB() {
BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = argbImage.getGraphics();
long len = width * height;
for (int i = 0; i < len; i++) {
int lonSimilar = i % width;
// no need for width - y as coordinate system for Graphics is already this way
int latSimilar = i / height;
int green = Math.abs(heights.getShort(i * 2));
if (green == 0) {
g.setColor(new Color(255, 0, 0, 255));
} else {
int red = 0;
while (green > 255) {
green = green / 10;
red += 50;
}
if (red > 255)
red = 255;
g.setColor(new Color(red, green, 122, 255));
}
g.drawLine(lonSimilar, latSimilar, lonSimilar, latSimilar);
}
g.dispose();
return argbImage;
}
代码示例来源:origin: runelite/runelite
/**
* Copy an image
* @param src
* @return
*/
private static Image copy(Image src)
{
final int width = src.getWidth(null);
final int height = src.getHeight(null);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.drawImage(src, 0, 0, width, height, null);
graphics.dispose();
return image;
}
代码示例来源:origin: stackoverflow.com
BufferedImage bufImg = ImageIO.read( imageURL );
BufferedImage convertedImg = new BufferedImage(bufImg.getWidth(), bufImg.getHeight(), BufferedImage.TYPE_USHORT_565_RGB);
convertedImg.getGraphics().drawImage(bufImg, 0, 0, null);
代码示例来源:origin: MovingBlocks/Terasology
private BufferedImage generateAtlas(int mipMapLevel, List<BlockTile> tileImages, Color clearColor) {
int size = atlasSize / (1 << mipMapLevel);
int textureSize = tileSize / (1 << mipMapLevel);
int tilesPerDim = atlasSize / tileSize;
BufferedImage result = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics g = result.getGraphics();
g.setColor(clearColor);
for (int index = 0; index < tileImages.size(); ++index) {
int posX = (index) % tilesPerDim;
int posY = (index) / tilesPerDim;
BlockTile tile = tileImages.get(index);
if (tile != null) {
g.drawImage(tile.getImage().getScaledInstance(textureSize, textureSize, Image.SCALE_SMOOTH), posX * textureSize, posY * textureSize, null);
} else {
g.fillRect(posX * textureSize, posY * textureSize, textureSize, textureSize);
}
}
return result;
}
}
代码示例来源:origin: plantuml/plantuml
private static BufferedImage readImage(final ImageIcon imageIcon) {
final Image tmpImage = imageIcon.getImage();
final BufferedImage image = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
BufferedImage.TYPE_INT_ARGB);
image.getGraphics().drawImage(tmpImage, 0, 0, null);
tmpImage.flush();
return image;
}
代码示例来源:origin: linlinjava/litemall
private void drawTextInImgCenter(BufferedImage baseImage, String textToWrite, int y) {
Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
g2D.setColor(new Color(167, 136, 69));
String fontName = "Microsoft YaHei";
Font f = new Font(fontName, Font.PLAIN, 28);
g2D.setFont(f);
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// 计算文字长度,计算居中的x点坐标
FontMetrics fm = g2D.getFontMetrics(f);
int textWidth = fm.stringWidth(textToWrite);
int widthX = (baseImage.getWidth() - textWidth) / 2;
// 表示这段文字在图片上的位置(x,y) .第一个是你设置的内容。
g2D.drawString(textToWrite, widthX, y);
// 释放对象
g2D.dispose();
}
代码示例来源:origin: stackoverflow.com
BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = image.getGraphics();
graphics.setColor(c);
graphics.fillRect(50, 50, 100, 100);
graphics.dispose();
代码示例来源:origin: stackoverflow.com
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_GRAY);
Graphics g = image.getGraphics();
g.drawImage(colorImage, 0, 0, null);
g.dispose();
代码示例来源:origin: libgdx/libgdx
public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
BufferedImage scratchImage = EffectUtil.getScratchImage();
filter.filter(image, scratchImage);
image.getGraphics().drawImage(scratchImage, 0, 0, null);
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws Exception {
final BufferedImage image = ImageIO.read(new URL(
"http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"));
Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(30f));
g.drawString("Hello World!", 100, 100);
g.dispose();
ImageIO.write(image, "png", new File("test.png"));
}
代码示例来源:origin: stackoverflow.com
public static BufferedImage copyImage(BufferedImage source){
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
Graphics g = b.getGraphics();
g.drawImage(source, 0, 0, null);
g.dispose();
return b;
}
代码示例来源:origin: libgdx/libgdx
static Icon getColorIcon (java.awt.Color color) {
BufferedImage image = new BufferedImage(32, 16, BufferedImage.TYPE_INT_RGB);
java.awt.Graphics g = image.getGraphics();
g.setColor(color);
g.fillRect(1, 1, 30, 14);
g.setColor(java.awt.Color.black);
g.drawRect(0, 0, 31, 15);
return new ImageIcon(image);
}
代码示例来源:origin: wuyouzhuguli/SpringAll
private ImageCode createImageCode() {
int width = 100; // 验证码图片宽度
int height = 36; // 验证码图片长度
int length = 4; // 验证码位数
int expireIn = 60; // 验证码有效时间 60s
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman", Font.ITALIC, 20));
g.setColor(getRandColor(160, 200));
for (int i = 0; i < 155; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
}
StringBuilder sRand = new StringBuilder();
for (int i = 0; i < length; i++) {
String rand = String.valueOf(random.nextInt(10));
sRand.append(rand);
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 13 * i + 6, 16);
}
g.dispose();
return new ImageCode(image, sRand.toString(), expireIn);
}
代码示例来源:origin: JpressProjects/jpress
/**
* 高保真缩放
*/
private static BufferedImage resize(BufferedImage bi, int toWidth, int toHeight) {
Graphics g = null;
try {
Image scaledImage = bi.getScaledInstance(toWidth, toHeight, Image.SCALE_SMOOTH);
BufferedImage ret = new BufferedImage(toWidth, toHeight, BufferedImage.TYPE_INT_RGB);
g = ret.getGraphics();
g.drawImage(scaledImage, 0, 0, null);
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (g != null) {
g.dispose();
}
}
}
代码示例来源:origin: stackoverflow.com
final float FACTOR = 4f;
BufferedImage img = ImageIO.read(new File("graphic.png"));
int scaleX = (int) (img.getWidth() * FACTOR);
int scaleY = (int) (img.getHeight() * FACTOR);
Image image = img.getScaledInstance(scaleX, scaleY, Image.SCALE_SMOOTH);
BufferedImage buffered = new BufferedImage(scaleX, scaleY, TYPE);
buffered.getGraphics().drawImage(image, 0, 0 , null);
代码示例来源:origin: kennycason/kumo
public BufferedImage getBufferedImage() {
final BufferedImage bufferedImage = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_ARGB);
final Graphics graphics = bufferedImage.getGraphics();
graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, dimension.width, dimension.height);
for (final WordCloud wordCloud : wordClouds) {
graphics.drawImage(wordCloud.getBufferedImage(), 0, 0, null);
}
return bufferedImage;
}
代码示例来源:origin: runelite/runelite
private void takeScreenshot(String fileName, Image image)
? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = screenshot.getGraphics();
graphics.drawImage(image, gameOffsetX, gameOffsetY, null);
内容来源于网络,如有侵权,请联系作者删除!