use of java.awt.Graphics in project HongsCORE by ihongs.
the class Thumb method draw.
/**
* 创建图层
* @param img 源图
* @param col 背景颜色
* @param w 目标宽
* @param h 目标高
* @return 新的图层
*/
private BufferedImage draw(BufferedImage img, Color col, int w, int h) {
BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics grp = buf.createGraphics();
if (col != null) {
grp.setColor(col);
grp.fillRect(0, 0, w, h);
}
grp.drawImage(img, 0, 0, null);
grp.dispose();
return buf;
}
use of java.awt.Graphics in project suite by stupidsing.
the class AnimationMain method run.
protected boolean run(String[] args) throws InterruptedException {
JFrame frame = new JFrame("Animation");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(new Dimension(1024, 768));
frame.setVisible(true);
PaintInput pi = new PaintInput();
frame.getContentPane().add(new JPanel() {
private static final long serialVersionUID = 1l;
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
Graphics2D g2d = (Graphics2D) graphics;
g2d.setColor(Color.BLACK);
g2d.fillRect(pi.i, pi.i, 32, 32);
}
});
ScheduledExecutorService executor = Executors.newScheduledThreadPool(4);
executor.scheduleAtFixedRate(() -> {
pi.i++;
frame.repaint();
}, 10, 10, TimeUnit.MILLISECONDS);
executor.awaitTermination(100, TimeUnit.SECONDS);
return true;
}
use of java.awt.Graphics in project cxf by apache.
the class SwAOutInterceptor method convertToBufferedImage.
private BufferedImage convertToBufferedImage(Image image) throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage) image;
}
// Wait until the image is completely loaded
MediaTracker tracker = new MediaTracker(new Component() {
private static final long serialVersionUID = 6412221228374321325L;
});
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
throw new Fault(e);
}
// Create a BufferedImage so we can write it out later
BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics g = bufImage.createGraphics();
g.drawImage(image, 0, 0, null);
return bufImage;
}
use of java.awt.Graphics in project Java by bottleleung.
the class Bitmap method createScaledBitmap.
/**
* ����ͼƬ
* @param src
* @param width
* @param height
* @param tf
*/
public static Bitmap createScaledBitmap(Bitmap src, int width, int height, boolean tf) {
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = img.getGraphics();
g.drawImage(src.image, 0, 0, width, height, 0, 0, src.getWidth(), src.getHeight(), null);
return new Bitmap(img);
}
use of java.awt.Graphics in project cxf by apache.
the class ImageHelper method convertToBufferedImage.
private static BufferedImage convertToBufferedImage(Image image) throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage) image;
}
/*not sure how this is used*/
MediaTracker tracker = new MediaTracker(null);
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
throw new IOException(e.getMessage());
}
BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bufImage.createGraphics();
g.drawImage(image, 0, 0, null);
return bufImage;
}
Aggregations