本文整理汇总了Java中javax.swing.ImageIcon.paintIcon方法的典型用法代码示例。如果您正苦于以下问题:Java ImageIcon.paintIcon方法的具体用法?Java ImageIcon.paintIcon怎么用?Java ImageIcon.paintIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.ImageIcon
的用法示例。
在下文中一共展示了ImageIcon.paintIcon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBackgroundImage
import javax.swing.ImageIcon; //导入方法依赖的package包/类
public void setBackgroundImage(Image image) {
if (image != null) {
final ImageIcon icon = new ImageIcon(image);
logoSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
final BufferedImage img =
ImageUtils.createCompatibleTranslucentImage(logoSize.width,
logoSize.height);
Graphics2D g = img.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
icon.paintIcon(null, g, 0, 0);
g.dispose();
UIManager.put("wizard.sidebar.image", img); //$NON-NLS-1$
}
}
示例2: serialize
import javax.swing.ImageIcon; //导入方法依赖的package包/类
@Override
public void serialize(ImageIcon vi, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
synchronized (vi) {
BufferedImage v = new BufferedImage(
vi.getIconWidth(),
vi.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics g = v.createGraphics();
// paint the Icon to the BufferedImage.
vi.paintIcon(null, g, 0, 0);
g.dispose();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(v, "png", baos);
byte [] data = baos.toByteArray();
jgen.writeStartObject();
jgen.writeStringField("type", "ImageIcon");
jgen.writeObjectField("imageData", data);
jgen.writeNumberField("width", v.getWidth());
jgen.writeNumberField("height", v.getHeight());
jgen.writeEndObject();
}
}
示例3: toBufferedImage
import javax.swing.ImageIcon; //导入方法依赖的package包/类
public static BufferedImage toBufferedImage(final ImageIcon icon) {
if (icon == null) return null;
final int w = icon.getIconWidth(), h = icon.getIconHeight();
final BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
final Graphics g = bi.createGraphics();
icon.paintIcon(null, g, 0,0);
g.dispose();
return bi;
}